JA
header image

枝折 - bookmark

Fixed-Point and Floating-Point Numbers

CS

CREATED: 2026 / 05 / 07 Thu

UPDATED: 2026 / 05 / 07 Thu

Fixed-Point and Floating-Point Numbers

Handling Fractions in Computers

When a computer works with fractional numbers, they generally fall into one of two categories:

  • Fixed-point numbers
  • Floating-point numbers

A fixed-point number is a numeric type where the lengths of the integer part and the fractional part are fixed. As a result, its expressive range is limited, and it struggles with very large and very small numbers at the same time.

A floating-point number is a numeric type where the fractional part can be held more flexibly, depending on whether single or double precision is used.

Fixed-Point Numbers

A fixed-point number has a predetermined binary point position. For example, with 8 bits split into 4 integer bits and 4 fractional bits, 00101011 is interpreted as follows:

Integer part:    0010 = 2
Fractional part: 1011 = 0.5 + 0.125 + 0.0625 = 0.6875
→ 2.6875

Simple, but limited in expressive power.

Floating-Point Numbers

A floating-point number moves the binary point through normalization, enabling a wider range of values and finer precision.

Modern computers widely use floating-point numbers based on the IEEE 754 standard.

Single-Precision and Double-Precision

IEEE 754 primarily defines two formats:

FormatBitsSignExponentMantissa
Single-precision(float)32 bits1 bit8 bits23 bits
Double-precision(double)64 bits1 bit11 bits52 bits

Double-precision offers a wider range and higher precision than single-precision, but uses twice as much memory.

The IEEE 754 standard splits a floating-point number into a sign field, an exponent field, and a mantissa field — more on that in the next section.

IEEE 754 Format

Sign, Exponent, and Mantissa

A floating-point number consists of three fields:

  • Sign bit(sign bit): 0 for positive, 1 for negative.
  • Exponent(exponent): Stores the base-2 exponent using biased representation.
  • Mantissa(mantissa): Stores the fractional digits of the significand.

For single-precision (32 bits), the bit layout is:

[sign 1bit][exponent 8bit][mantissa 23bit]

Normalization

IEEE 754 stores the mantissa in normalized form.

Normalization means converting a value into the form 1.xxxxx × 2^e.

Because the integer part is always 1, it is never stored explicitly — this is the implicit leading 1. Thanks to this, the 23-bit mantissa effectively carries 24 bits of precision.

Example: Represent the decimal fraction 13.625(10) as a single-precision float.

Integer part:    13    = 1101(2)
Fractional part: 0.625 = 0.101(2)

13.625 = 1101.101(2)
       = 1.101101 × 2^3  ← normalized

Sign bit: 0 (positive)
Exponent: 3 + 127 (bias) = 130 = 10000010(2)
Mantissa: 10110100000000000000000 (101101 padded to 23 bits with zeros)

Biased Exponent

The exponent field uses a bias to represent negative exponents.

Just as two’s complement is one way to represent negative numbers, IEEE 754 uses a bias instead. This allows a negative exponent to still be stored as a non-negative binary value.

stored value  = actual exponent + bias
actual exponent = stored value − bias

The bias depends on the precision:

PrecisionBiasActual exponent range
Single-precision127-126 to +127
Double-precision1023-1022 to +1023

These are determined by 2^(exponent bits − 1) − 1. For single-precision: 2^(8-1) − 1 = 127; for double-precision: 2^(11-1) − 1 = 1023.

Differences from Two’s Complement

Comparing two’s complement and biased representation reveals different purposes and mechanisms:

PropertyTwo’s complementBiased representation
Primary useSigned integer mathFloating-point exponent field
How negatives workBit-flip + 1Stored value − bias

The reason biased representation is used for the exponent is that the stored value can be compared directly as an unsigned integer, regardless of sign. This means floating-point magnitude comparison can be performed with a simple bitwise integer comparison of the entire number — no bit-flipping required, unlike two’s complement.

Decimal(Decimal Fractions)

Exponent Notation e

In programming, e (or E) is used to write floating-point numbers in exponential notation. 1.5e3 means 1.5 × 10^3 = 1500.

1.5e3   →  1500.0
3.0e-2  →  0.03
6.02e23 →  6.02 × 10^23 (e.g., Avogadro's number)

Rounding Errors

Related to fractions, let’s also look at the errors that arise between decimal fractions and binary fractions.

When a decimal fraction is stored in a database, it is handled internally as a binary value. But not every decimal fraction can be expressed as a finite binary fraction.

As shown below, 0.5(10) and 0.25(10) are finite in binary, but 0.1(10) and 0.3(10) become infinitely repeating binary fractions:

0.5(10)  = 0.1(2)                        ← finite
0.25(10) = 0.01(2)                       ← finite
0.1(10)  = 0.00011001100110011...(2)     ← infinitely repeating
0.3(10)  = 0.01001100110011001...(2)     ← infinitely repeating

No system can store an infinite value — doing so would fill memory instantly. So the number of digits is capped (say, 10 decimal places), which means infinite fractions must be cut short. Cutting them introduces truncation or rounding.

This causes a discrepancy between the original decimal value that was input and the decimal value reconstructed when reading back from storage. This is the rounding error.

A classic example:

0.1 + 0.2 = 0.30000000000000004

Because 0.1 and 0.2 cannot be represented exactly in binary floating-point, each carries a tiny error that surfaces in the result.

One mitigation strategy in MySQL, for example, is to use the Decimal type (a type that handles decimal fractions as exact decimal values). Though it ultimately depends on the tools and language you’re working with.

Closing

References 📕