| 1 |
|
| 2 |
|
| 3 |
ACME |
| 4 |
|
| 5 |
...the ACME Crossassembler for Multiple Environments |
| 6 |
|
| 7 |
--- floating-point support --- |
| 8 |
|
| 9 |
|
| 10 |
In release 0.92, ACME gained some experimental support for floating- |
| 11 |
point maths, so you can finally build sin/cos tables directly in ACME. |
| 12 |
But the expression parser still uses integer calculations per default. |
| 13 |
Here are the rules: |
| 14 |
|
| 15 |
a) if a maths operation is useless when done with integers, it is done |
| 16 |
with floats and returns a float. Applies to sin(), cos(), tan(), |
| 17 |
arcsin(), arccos(), arctan() and float(): These are always computed in |
| 18 |
float mode and always return floats. |
| 19 |
|
| 20 |
b) if a maths operation is useless when done with floats, it is done |
| 21 |
with integers and returns an integer. Applies to NOT, AND, OR, XOR, |
| 22 |
MOD, DIV, LSR, lowbyteof, highbyteof, bankbyteof and int(). These are |
| 23 |
always computed in integer mode and always return integers. |
| 24 |
|
| 25 |
c) All other mathematical operations are done in float mode if and |
| 26 |
only if at least one of the operands is a float. So "1/2*2" will give |
| 27 |
zero because it is done in integer mode, but "1.0/2*2" will give 1 |
| 28 |
because it is done in float mode. |
| 29 |
|
| 30 |
To force a numerical value to be flagged as being a float, just add |
| 31 |
a decimal point and a zero. If a decimal value ends with a |
| 32 |
dot character, ACME switches to using the C type "double" and keeps |
| 33 |
reading digits. The value is then flagged internally as being float. |
| 34 |
CAUTION: Float usage is only activated when a decimal point has been |
| 35 |
found, so don't expect "100000000000000000000" to work. |
| 36 |
"100000000000000000000.0" won't work either, because when the decimal |
| 37 |
point gets parsed, the integer value will have overflown already. As |
| 38 |
there is no support yet for the "e" format (1e20 for 1*10^20) either, |
| 39 |
the only way to enter this value is by writing "1.0 * 10.0 ^ 20.0". |
| 40 |
|
| 41 |
Examples: |
| 42 |
|
| 43 |
!byte 1 / 2 * 2 ; gives 0 (integer maths) |
| 44 |
!byte 1 / 2 * 2.0 ; gives 0 (1/2 -> 0 in integer maths, |
| 45 |
; float usage comes too late) |
| 46 |
!byte 1 / 2.0 * 2 ; gives 1 (FP in effect) |
| 47 |
!byte 1 / 2.0 * 2.0 ; gives 1 (FP in effect) |
| 48 |
!byte 1.0 / 2 * 2 ; gives 1 (FP in effect) |
| 49 |
!byte 1.0 / 2 * 2.0 ; gives 1 (FP in effect) |
| 50 |
!byte 1.0 / 2.0 * 2 ; gives 1 (FP in effect) |
| 51 |
!byte 1.0 / 2.0 * 2.0 ; gives 1 (FP in effect) |
| 52 |
|
| 53 |
You can use the new float() and int() functions to ensure the type of |
| 54 |
maths: |
| 55 |
|
| 56 |
!byte a / b * c ; depends on a/b/c's internal flags |
| 57 |
!byte float(a) / b * c ; calculation is done as float |
| 58 |
!byte int(a) / int(b) * int(c) ; calculation is done as int |
| 59 |
|
| 60 |
As you will have guessed, the trigonometric functions assume radians |
| 61 |
for measuring angles (90 degrees equals PI/2). |
| 62 |
|
| 63 |
Have a look at the example source code "trigono.a", it builds some |
| 64 |
sin/cos tables. |