Fixed-point expressions

Fixed point constants are basically normal 32-bit constants where the upper 16 bits are used for the integer part and the lower 16 bits are used for the fraction (65536ths). This means that you can use them in normal integer expression and indeed some integer operators like plus and minus don't care whether the operands are integer or fixed-point. You can easily convert a fixed-point number to an integer by shifting it right 16 bits. It follows that you can convert an integer to a fixed-point number by shifting it left.

Some things are different for fixed-point math though. Which is why you have the following functions to use:
Name Operation
DIV(x,y) x/y
MUL(x,y) x*y
SIN(x) sin(x)
COS(x) cos(x)
TAN(x) tan(x)
ASIN(x) sin-1(x)
ACOS(x) cos-1(x)
ATAN(x) tan-1(x)
ATAN2(x,y) (x,y) angle

These functions are extremely useful for automatic generation of various tables. A circle has 65536.0 degrees. Sine values are between [-1.0;1.0]

; --

; -- Generate a 256 byte sine table with values between 0 and 128

; --

ANGLE   SET     0.0

        REPT    256

        DB      (MUL(64.0,SIN(ANGLE))+64.0)>>16

ANGLE   SET     ANGLE+256.0


See also:

Last updated 21 June 1997 by Carsten Sorensen