Fixed Point and Floating Point
Computers store everything as 0s and 1s, so to store a real number like 3.14 you need a rule for "where to put the decimal point." There are two such rules: fixed point and floating point.
At a Glance
- Fixed point: the position of the decimal point is decided in advance.
- Analogy: a price tag with a fixed number of boxes. If you set it to "5 integer boxes, 2 fraction boxes," you can only write things like
00123.45. It is simple, but very large or very small numbers don't fit in the boxes.
- Analogy: a price tag with a fixed number of boxes. If you set it to "5 integer boxes, 2 fraction boxes," you can only write things like
- Floating point: the position of the decimal point is written down separately along with the number. "Floating" means the point drifts and moves.
- Analogy: the scientific notation from science class,
1.23 × 10 to the 5th power. Since the significant digits (1.23) and "how many places to move the decimal point" (5) are written separately, very large and very small numbers can be expressed with the same number of boxes.
- Analogy: the scientific notation from science class,
Fixed Point
A way of representing fractions by deciding in advance where the decimal point goes (integer part + fractional part)
For example, to represent -3.141592 you need three elements: the sign (-), the integer part (3), and the fractional part (0.141592).
As an example using 32 bits, splitting them into 1 sign bit, 15 integer bits, and 16 fraction bits looks like this.

Image source: TCP School, Floating-point types
1 bit 15 bits 16 bits
┌──────┬────────────────────┬────────────────────┐
│ Sign │ Integer part │ Fractional part │
└──────┴────────────────────┴────────────────────┘
▲
The decimal point is fixed here- Pros: it is simple, since a real number is represented split into an integer part and a fractional part. It is effectively stored and computed as a single integer, so operations are as fast and predictable as integer operations.
- Cons: the range it can represent is narrow. In the example above, the integer part has only 15 bits, so it only goes up to about ±32767, and the fractional part has 16 bits, so it can't represent anything finer than 1 over 2 to the 16th power (about 0.0000153).
How many bits go to the integer part and the fractional part is not a fixed rule; the designer decides. 15 and 16 bits are just one commonly used example.
In Code
Fixed point with 16 bits for the fractional part is the same as "multiplying the real number by 2 to the 16th power (65536) and storing it as an integer."
# Fixed point with 16 bits for the fraction (stored in units of 1 divided by 2**16 = 65536)
SCALE = 2 ** 16
def to_fixed(x):
return round(x * SCALE) # stored as a single integer
def from_fixed(n):
return n / SCALE
a = to_fixed(-3.141592)
print(a) # the integer actually stored
print(from_fixed(a)) # converted back to a real number
print(from_fixed(to_fixed(1.5) + to_fixed(2.25))) # addition is just integer addition
print(1 / SCALE) # the smallest representable step-205887
-3.1415863037109375
3.75
1.52587890625e-05-3.141592 became slightly different, -3.1415863.... This is because the fractional part has only 16 bits, so it can't be stored any more precisely. Fixed point is not error-free either; its characteristic is that the size of the error is constant.
Floating Point
A way of representing a real number as mantissa + exponent
- Mantissa: represents the actual value (significant digits) of the real number.
- Exponent: represents the magnitude. It indicates where in the mantissa the decimal point sits.
It is a real-number representation that uses a decimal point that moves according to the value of the exponent. In other words, the position of the decimal point is not fixed.
Structure of 32-bit Floating Point (IEEE 754)
Almost every computer today follows a standard called IEEE 754. 32 bits (single precision, float) are split like this.

Image source: TCP School, Floating-point types
1 bit 8 bits 23 bits
┌──────┬──────────────┬──────────────────────────────────┐
│ Sign │ Exponent │ Mantissa │
└──────┴──────────────┴──────────────────────────────────┘
value = (-1)^sign × 1.mantissa × 2^(exponent - 127)- If you put a binary number in the form
1.xxxx × 2 to the n-th power(normalization), the leading digit is always 1, so that 1 is not stored and only the 23 bits after the point are stored in the mantissa. - The exponent also needs negative values, so the actual exponent plus 127 is stored. This 127 is called the bias.
- 64 bits (double precision, double) use 1 sign bit, 11 exponent bits, and 52 mantissa bits. Python's
floatis 64-bit.
In Code
Let's check directly how a real number is stored in 32 bits using Python's struct module.
import struct
def float32_bits(x):
# Returns the bits, as strings, of a real number stored as 32-bit floating point
n = struct.unpack('>I', struct.pack('>f', x))[0]
b = f'{n:032b}'
return b[0], b[1:9], b[9:]
for x in [-3.141592, 0.1]:
s, e, m = float32_bits(x)
print(f'{x}: sign={s} exponent={e} ({int(e, 2)} - 127 = {int(e, 2) - 127}) mantissa={m}')
print(0.1 + 0.2)
print(0.1 + 0.2 == 0.3)
print(struct.unpack('>f', struct.pack('>f', 0.1))[0])-3.141592: sign=1 exponent=10000000 (128 - 127 = 1) mantissa=10010010000111111011000
0.1: sign=0 exponent=01111011 (123 - 127 = -4) mantissa=10011001100110011001101
0.30000000000000004
False
0.10000000149011612-3.141592is negative, so its sign is 1, and it is stored as1.57... × 2 to the 1st power, so the actual exponent is 1.- The mantissa of
0.1repeats1001 1001 1001...endlessly and is cut off at 23 bits. This is because 0.1 is a number that doesn't divide evenly in binary. - That is why
0.1 + 0.2doesn't come out to exactly0.3, and reading back a 0.1 stored in 32 bits gives0.10000000149....
Pros and Cons
- Pros: with the same number of bits, the range of numbers it can represent is much wider. A 32-bit float can represent roughly 10 to the -38th power up to 10 to the 38th power. That is why most systems today use this method for real numbers.
- Cons: errors can occur. There are two reasons.
- The number of mantissa bits is fixed, so numbers longer than that are rounded and cut off.
- Even a number like 0.1 that is exact in decimal is an infinitely repeating fraction in binary, so it can't be stored exactly.
- Also, the larger the number, the wider the gap between representable values. When you add a large number and a very small number, the small number can even be ignored.
When to Use Which
When Fixed Point Is Used
- Embedded systems and microcontrollers: in environments with limited memory and processing power, fixed-point arithmetic is common. The hardware that supports floating-point operations (FPU) may not exist, or even if it does, it can use a lot of battery or other resources.
- Real-time systems: fixed point is preferred in programs whose execution time must be predictable. Floating-point operations can vary in execution time depending on the case, such as when they hit very small numbers (denormalized numbers).
- Cost-sensitive hardware: adding a floating-point unit can cost more, so fixed point is sometimes used to lower the price.
- Digital signal processing (DSP): some signal processing algorithms have a precisely defined value range, so fixed point is often enough.
- Money calculations: since even a 0.1 won error is a problem for amounts, instead of floating point they are stored as "integers in won" or "integers in cents," or handled with exact decimal types like Python's
decimal. Fixing the number of decimal places is the same idea as fixed point.
When Floating Point Is Used
- Scientific computing: scientific and engineering calculations that need a wide range of values and high precision
- 3D graphics: graphics work like 3D modeling that has to handle very large and very small values together
- Financial analysis: calculations like complex financial modeling, risk assessment, and statistical analysis, where approximate values are good enough and the range is wide. However, as mentioned above, floating point is not used for calculations that store and settle actual amounts of money.
- Computer simulation: calculations like physical system simulations that need a wide range of values and high precision
Conclusion
- Fixed point is mainly used in environments where resources are limited, the value range is narrow, and precision requirements are not high.
- Floating point is suited to complex calculations that need a wide range and high precision.
- Modern processors have become very fast at floating-point operations too, so the performance gap between the two is not as big as it used to be.
- When comparing real numbers, it is safer to check "whether the difference is very small" instead of
a == b. (Python'smath.isclose)
Summary
| Concept | Plain-language summary |
|---|---|
| Fixed point | The decimal position is set in advance. Simple and fast, but the range is narrow |
| Floating point | Stores the significant digits and "how many places the point moves" separately. Wide range |
| Mantissa | The significant digits part (1.23 in 1.23 × 10 to the 5th power) |
| Exponent | How many places to move the decimal point (5 in the example above) |
| IEEE 754 | The international standard for storing floating point. A float is 1 + 8 + 23 bits |
| Floating-point error | Numbers like 0.1 that aren't exact in binary are stored as approximations |
| Money calculations | Use integers (won/cent units) or decimal instead of floating point |
