Overview
Fixed Point theory and history Floating Point to Fixed Point Maintain accuracy avoid overflows and optimization tricks Effective use of Fixed Point in OpenGL ES
Floats format
Floating format is now the commonly used number format for 3D operations. Instead of always multiply by a fixed exponent as in Fixed Point, It uses Exponent: Float a = mantissa*2^(exponent-127)
So : Float = mantissa*2^(exponent-127)
Fixed = number*2^16
ARM architecture
Designed for low power consumption so : No floating point support in mainstream ARM7 ARM9 cores No divide support in ARM7 Small cache memory L1 and no L2
Easy to implements
So Fixed Points fit perfectly to ARM cores No needs for DSP or FPU Caution of Divide support And cache memory
A fixed point number has limited accuracy. You must choose small numbers and inputs a normalize data as possible.
Overflow underflow
Overflow
- An "overflow" will occur when the result of a arithmetic operation is too large to fit into the fixed representation of a fixed point number a = 0x7FFF << 16 b = 0x20 << 16 a += b // An overflow
Underflow
When you used a not enough accurate value for fraction, like in trigo maths But in fixed point no exception handling Using 64 intermediate numbers but speed consuming
Optimization tricks
Trigonometric operations Using LookupTable best with 1024 bytes size first quadrant and s8:24 for avoiding underflow. Square operations Using logarithm functions LUT are too big for small cache Use other fixed formats range s24:8 for larger numbers and convert to GLFixed: Fixed24_8Num = glFixedNum>>8 // You lost some precision but higher integer range If (Fixed24_8Num&0x7F000000 != 0) error // to big number Else glFixedNum = Fixed24_8Num<<8 // convert to GLFixed
Avoiding pitfalls
Overflow Integer Range Also divide errors (try to not use it)
Questions?