Fixed point maths - Falmouth-Games-Academy/comp310-wiki GitHub Wiki
Fixed-point arithmetic/maths is a data type used for a number that has a fixed amount of digits before or after the radix/decimal point [1]. Fixed-point representation is a much more simplistic and less computationally demanding than floating-point numbers. The author of [4] disagrees with the "simplistic" part of this statement. In [4], the author describes fixed-point maths as "much less convenient" to work with. Some older or cheaper microprocessors do not have an FPU (floating point unit) which means that fixed point numbers offer both improved accuracy and performance on these machines. They are useful for representing fractional values, commonly in base 2 or 10.
The value of a fixed-point is similar to an integer that is scaled based on an implicit factor determined by the type. This basically means the number 1.23 can be represented as 1230 and the scaling factor would be 1/1000, whereas the value 1,230,000 can be represented the same but the scaling factor would be 1000. A key difference between this and floating-point data types is that the scaling factor is the same for every value of the same data type and does not change during runtime1(https://en.wikipedia.org/wiki/Fixed-point_arithmetic).
For addition and subtraction, the radix point stays where it started so we can treat it them like integers. However for multiplication, we have to move the radix point left by the number of fraction bits, we also have to normalize the result afterwards by shifting the result right by the number of fraction bits. You can read more about multiplication here
Information loss is possible in fixed-point arithmetic due to the possibility that the results can produce more bits than the operands. For example, the result of multiplication can potentially have equal or more bits than the sum of the two operands. Therefore we have to perform rounding or truncation to balance the number of bits and operands. The choice of bits to keep is very important, however, the most common and simple method used where the procedures use the same result format as the operands which effectively keeps the middle bits.
Most computer programming languages don't include support for fixed-point math because for most applications floating point representations are both simpler and accurate enough to use.