Summary of The Art of Representing Floating-Point Numbers as Integers
This article argues that using floating-point variables on embedded systems without a Floating-Point Unit (FPU) is inefficient. It recommends converting numbers to fixed-point representation using integers and scaling values to optimize performance and code size. The text explains the mathematical limits of CPU registers, defines Q-format notation for separating integer and fractional bits, and emphasizes selecting bit allocations based on architecture precision needs.
Parts used in Fixed-Point Representation Project:
- Floating-point variables
- Double variables
- Floating-Point Unit (FPU)
- C/C++ compiler
- Assembly code generator
- CPU architecture registers
- CPU buses
- Two's complement system
- Q-format notation
- Scaling value
Have you been using float or double variables to perform mathematical operations on embedded systems without a Floating-Point Unit (FPU)? You are doing it wrong! That’s incredibly inefficient. Use fixed-point representation instead.
An FPU is an hardware block specially designed to carry on arithmetic operations on floating point numbers. Even though the C/C++ code may work without an FPU, it’s always much faster to use hardware designed for a specific purpose, like this one, instead of relying on a software implementation, something that the compiler will do for you, knowing the hardware restrictions you have but not in an efficient manner. Essentially, it will generate a lot of assembly code, greatly increasing the size of your program and the amount of time required to complete the operation. Thus, if you don’t have an FPU available and you still want to perform those arithmetic operations efficiently you’ll have to convert those numbers to fixed-point representation. Integers! But how? By scaling them. Let’s see how that scaling value may be determined.
The scaling value as well as the resulting scaled number, which is an integer, really much depends on the bitness of the CPU’s architecture being used. You want to use values that fit in the available registers which have the same width as the CPU buses. So, whether you are working with an 8, 16 or 32-bit architecture, the range of integer values we can store on those registers, being b the number of bits and representing numbers in two’s complement, is given by:
Fixed-Point Representation
If one bit is used to represent the sign (and in this text we’ll always consider signed numbers) the remaining ones may be used to represent the integer and fractional parts of the floating-point number.We may textually represent this format as follows (denoted as Q-format):
Where m corresponds to the bits available to represent the integer part of and n corresponds to the bits available to represent the fractional part. If m is zero you may use just Qn
. So, when you use a register to save both integer and fractional parts (and the sign bit!), the value range is then given by:
(note that the expression above is a particular case of this one, for n=0 and m=b-1).
It’s up to you deciding how many bits are reserved for m and n (still, you should base your decision on a good criteria: the more bits, the greater the precision you can achieve; more on this bellow). So, you are essentially fixing an imaginary point in your register that separates the integer and fractional parts. That’s why it’s called fixed-point.
For more detail: The Art of Representing Floating-Point Numbers as Integers
-
Why should you avoid float or double variables on embedded systems without an FPU?
Using them is inefficient because the compiler generates excessive assembly code, increasing program size and execution time compared to hardware-specific operations. -
What is the recommended alternative to floating-point arithmetic on systems lacking an FPU?
You should use fixed-point representation by converting numbers to integers through scaling. -
How does the scaling value relate to the CPU architecture?
The scaling value depends on the bitness of the CPU architecture, ensuring values fit within available registers matching the bus width. -
What is the formula for the range of integer values in a b-bit register using two's complement?
The range is given by −2^(b−1) ≤ value ≤ 2^(b−1) – 1. -
How is the Q-format notation defined in terms of bit allocation?
Qm.n denotes m bits for the integer part and n bits for the fractional part, with one bit reserved for the sign. -
What determines the trade-off between precision and range in fixed-point representation?
The number of bits allocated to the integer and fractional parts determines precision; more bits generally yield greater precision.






