Fixed point number, Differences from floating point numbers



Digital signal processing

Release date:2023/8/2         

In Japanese
Premise knowledge
Binary number
Floating point number


■Fixed-point number LSB and OFFSET

Fixed-point numbers have a fixed decimal place, whereas floating-point numbers change their decimal place according to the size of the number. For example, if it is defined to be expressed in 2 decimal places, the value will be in increments of 0.01. This 0.01 is called LSB (Least Significant Bit) or resolution. You can also offset the value and determine the minimum value of the data. for example,



■Fixed-point data type

The minimum data size for floating point is 4 bytes, but fixed point data size is smaller than 4 bytes, such as 1 byte or 2 bytes. When the data size is 1 byte, 256 values can be expressed, and when it is 2 bytes, 65536 values can be expressed.



■Fixed-point data range

The data range is determined from the LSB, OFFSET, and data size. for example,


LSB, OFFSET, and data size should be set appropriately according to the range of values you actually want to handle. For example, when trying to handle temperature data, if LSB = 0.01, OFFSET = -10, and data size is 1 byte as above, the range of values that can be handled is -10 to -7.45, so it is not suitable for handling temperature data. I understand that there is not. What kind of LSB, OFFSET, and data type are set depends on the skill of the designer. The following is a setting example for handling temperature data.



■Advantages of fixed point

① Data size can be reduced compared to floating point numbers.
When implementing a program on a microcomputer, it is very important to save the ROM usage of the microcomputer. In the NES (Nintendo Entertainment System), various devices were devised to save capacity, and one of them was the reduction of data to 1 byte. His Malroth, the final boss of Dragon Quest 2, has 255 HP, and it is well known that he was devised to compensate for his low HP by recovering all HP with the spell Fullheal. In addition, the capacity problem was not only a problem in the past, but it is still important in developing embedded software. Increasing the ROM capacity will lead to an increase in the cost of the microcomputer.

② Since the data that can be handled is fixed, it is suitable for comparing values.
As a problem when representing numbers with decimal points in binary numbers, binary numbers often become recurring decimals, and in the case of floating point numbers, approximation errors occur. Therefore, for example, even if you create a program "when A and B are equal", the computer may judge that the numbers do not match, even though the human is comparing the same numbers. In such a case, fixed-point conversion is suitable. Fixed point conversion does not mean that recurring decimals do not occur, and even if recurring decimals occur, the value is discarded.

■Disadvantages of fixed-point numbers

① It's easy to make mistakes and misunderstand because you have to set the LSB, OFFSET, and data type.
Setting the LSB, OFFSET, and data type depends on the skill of the designer and is subject to error. In addition, since the simulation software that runs on the PC before implementing it on the microcomputer may assume floating point, there is a possibility that the simulation and implementation results will not match.

② Processing overhead when converting from fixed-point numbers to floating-point numbers.
Not all programs implemented in current microcomputers use fixed-point numbers, and floating-point numbers are often used for ease of design. Fixed-point and floating-point numbers cannot be calculated, so fixed-point data must be converted to floating-point numbers, which adds processing overhead. However, in the case of programs that are all fixed point, fixed point seems to be able to operate faster.









List of related articles



Digital signal processing