Friday, June 2, 2023

Fixed point real number

Fixed point means the decimal point is fixed at a certain bit position.  For examples, one can use 8 bits for the number and another 8 bits for the fraction.  The number point is interpreted as the usual binary representation, signed or unsigned.  Each bit in the fraction part is interpreted based on its bit position.  The value at position n (counted from left to right) = 1/(2^n) or 2^-n

For example if the fraction = 10011111,

1/(2^1) = 1/2 = 0.5

0/(2^2) = 0/4 = 0

0/(2^3) = 0/8 = 0

1/(2^4) = 1/16 = 0.0625

1/(2^5) = 1/32 = 0.03125

1/(2^6) = 1/64 = 0.015625

1/(2^7) = 1/128 = 0.0078125

1/(2^8) = 1/256 = 0.00390625

The decimal value is = 0.5 + 0 + 0 + 0.0625 + 0.03125 + 0.015625 + 0.0078125 + 0.00390625 = 

Fixed point is popular in the past when floating point unit is not available.  Even with FPU become a standard hardware component equipped in all modern processor, fixed point is still used in game because it is still more efficient than floating point calculation   

Comparing to using BCD (binary coded decimal), fixed point has higher resolution  for example 8bits can be used to represent BCD values from .00 to .99  8 bus in fixed point representation can represent 2^n fraction value  

Fixed point still cannot be used to represent all real number and only an approximation (eg 1/3).


No comments: