You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Clarify the operator relationship of ordinary and fixed-point numbers
* Attempt to clarify description of fixed-point numbers
* Note that RGBASM does not check fixed-point precisions
* Simplify sine table example a bit
* Remove misleading equations describing `DIV`, `MUL`, and `FMOD`
* Various minor style and formatting fixups
Copy file name to clipboardexpand all lines: man/rgbasm.5
+65-34
Original file line number
Diff line number
Diff line change
@@ -369,43 +369,45 @@ equals $roman clz ( n )$.
369
369
delimoff
370
370
.EN
371
371
.SsFixed-pointexpressions
372
-
Fixed-point numbers are basically normal (32-bit) integers, which count fractions instead of whole numbers.
373
-
They offer better precision than integers but limit the range of values.
374
-
By default, the upper 16 bits are used for the integer part and the lower 16 bits are used for the fraction (65536ths).
375
-
The default number of fractional bits can be changed with the
372
+
Fixed-point numbers are technically just integers, but conceptually they have a decimal point at a fixed location (hence the name).
373
+
This gives them increased precision, at the cost of a smaller range, while remaining far cheaper to manipulate than floating-point numbers (which
374
+
.Nm
375
+
does not support).
376
+
.Pp
377
+
The default precision of all fixed-point numbers is 16 bits, meaning the lower 16 bits are used for the fractional part; so they count in 65536ths of 1.0.
378
+
This precision can be changed with the
376
379
.FlQ
377
-
command-line option.
378
-
You can also specify a precise fixed-point value by appending a
380
+
command-line option, and/or by
381
+
.IcOPTQ
382
+
.PqseeSxChangingoptionswhileassembling .
383
+
An individual fixed-point literal can specify its own precision, overriding the current default, by appending a
379
384
.Dqq
380
-
to it followed by the number of fractional bits, such as
381
-
.Ql12.34q8 .
385
+
followed by the number of fractional bits: for example,
386
+
.Ql1234.5q8
387
+
is equal to $0004d2_80
388
+
.EQ
389
+
delim$$
390
+
.EN
391
+
($= 1234.5 * 2 sup 8$).
382
392
.Pp
383
393
Since fixed-point values are still just integers, you can use them in normal integer expressions.
384
-
Some integer operators like
385
-
.Sq+
386
-
and
387
-
.Sq-
388
-
don't care whether the operands are integers or fixed-point.
389
394
You can easily truncate a fixed-point number into an integer by shifting it right by the number of fractional bits.
390
395
It follows that you can convert an integer to a fixed-point number by shifting it left that same amount.
391
396
.Pp
392
397
Note that the current number of fractional bits can be computed as
393
398
.IcTZCOUNTNsPq1.0 .
394
399
.Pp
395
400
The following functions are designed to operate with fixed-point numbers:
0 commit comments