Fixed Point Math - rosco-pc/propeller-wiki GitHub Wiki

Fixed point Math makes reference to a way of number representation that allows fast calculations without all the burden of a full floating point implementation with some floating point advantages, i.e decimal places. This article will be focused in 16.16 Fixed point numbers (aka FP16.16).

This representation has important properties:

There is no exponent The number is denormalized The fraction does not represent decimal digits, is a binary fraction.

The number one (1.0) is represented as $1_0000 The number two (2.0) is represented as $2_0000 The number 1/2 (0.5) is represented as $0_8000

Arithmetic

Addition and subtraction of two FP16.16 yields directly a FP16.16


    add  n1,n2
n1  long $1_0000
n2  long $2_0000


yields n1 = $3_0000

Multiplication is a bit more complicated because the result gets scaled as a consequence of taking the number of bits of both arguments added.


    mull  n1,n2     ' inexistent 32x32 multiplication, returns high 32 bits discards lower 32 bits
n1  long  $2_0000
n2  long  $3_0000

yields $6_0000


Division is a bit much more complicated, because scaling also occurs and all non-zero digits to the right of the decimal point will be lost:


    divl  n1,n2     ' hypothetic 32 by 32 bit division
n1  long  $5_0000   ' 5.0
n2  long  $0_8000   ' 0.5

will yield $0_000A, an unscaled result (should be $A_0000, 10.0)

    divl  n1,n2     ' hypothetic 32 by 32 bit division
n1  long  $5_0000   ' 5.0
n2  long  $0_4000   ' 0.25

will yield $0_0014, an unscaled result (should be $14_0000, 20.0)



((More to come))


Two fixpoint mandelbrot set programs in different FP math resolutions: