G27
Self-checkedTier 1 14 min readdl.ieee754

IEEE 754 floating point

The single and double precision formats: sign, biased exponent and fraction fields, normal numbers, denormals, zero, infinity and NaN, ranges and precision, rounding, and how to encode and decode a number by hand.

Why it exists

Fixed-point numbers have a fixed resolution, so they cannot hold both a galaxy's mass and an electron's. Scientific notation fixes this by separating the digits (the significand) from the scale (the exponent): −6.022×1023-6.022 \times 10^{23}. IEEE 754 is that idea in binary, standardised so that every processor stores, rounds and compares floating-point numbers in the same way. In GATE the format is tested in three ways: encode or decode a number by hand, reason about the largest, smallest and most precise values (including the special cases), and spot the surprises that follow from rounding.

Prerequisites

You need binary fractions (number systems) and the idea of a biased (excess) code from signed number representation.

Precise definitions

A binary floating-point word has three fields, from the most significant bit down: sign ss (1 bit), biased exponent ee (EE bits) and fraction ff (MM bits).

FormatTotalEEMMBiasHidden bit
single (binary32)32823127yes
double (binary64)6411521023yes

Let ee be the unsigned value of the exponent field, ff the unsigned value of the fraction field read as an integer, and write the fraction as the binary fraction f/2Mf / 2^{M}.

Normal numbers (0<e<2E−10 < e < 2^E - 1):

(−1)s×(1+f2M)×2 e−bias.(-1)^s \times \left(1 + \frac{f}{2^M}\right) \times 2^{\,e - \text{bias}}.

The leading 1 is not stored. It is the hidden bit (implicit leading 1), so the significand has M+1M + 1 bits of precision (24 for single, 53 for double). The exponent field ee is biased (excess code): the true exponent is e−biase - \text{bias}.

Zero (e=0e = 0, f=0f = 0): +0+0 and −0-0, two patterns that compare equal.

Denormal (subnormal) numbers (e=0e = 0, f≠0f \ne 0):

(−1)s×f2M×2 1−bias.(-1)^s \times \frac{f}{2^M} \times 2^{\,1 - \text{bias}}.

There is no hidden bit and the exponent is fixed at 1−bias1 - \text{bias} (−126-126 for single, −1022-1022 for double). They fill the gap between zero and the smallest normal number (gradual underflow).

Infinity (e=2E−1e = 2^E - 1, f=0f = 0): ±∞\pm\infty.

NaN, not a number (e=2E−1e = 2^E - 1, f≠0f \ne 0). There are 2(2M−1)2(2^M - 1) NaN patterns. A NaN is the result of an invalid operation such as 0/00/0 or ∞−∞\infty - \infty.

Key values.

singledouble
largest finite(2−2−23)×2127≈3.4028235×1038(2 - 2^{-23}) \times 2^{127} \approx 3.4028235 \times 10^{38}(2−2−52)×21023≈1.7976931×10308(2 - 2^{-52}) \times 2^{1023} \approx 1.7976931 \times 10^{308}
smallest normal2−126≈1.1754944×10−382^{-126} \approx 1.1754944 \times 10^{-38}2−1022≈2.2250739×10−3082^{-1022} \approx 2.2250739 \times 10^{-308}
smallest denormal2−149≈1.4×10−452^{-149} \approx 1.4 \times 10^{-45}2−1074≈4.9×10−3242^{-1074} \approx 4.9 \times 10^{-324}
spacing just above 1 (machine epsilon)2−232^{-23}2−522^{-52}
decimal digits of precisionabout 7.2about 15.95

Spacing. Within [2k,2k+1)[2^k, 2^{k+1}) the numbers are evenly spaced 2k−M2^{k - M} apart. So the absolute gap doubles every time the exponent grows by one, while the relative gap stays between 2−M−12^{-M-1} and 2−M2^{-M}. All integers up to 2242^{24} (single) or 2532^{53} (double) are exact.

Rounding. The default mode is round to nearest, ties to even: the result is the closest representable number, and when exactly halfway, the one whose last fraction bit is 0. Other modes are round toward zero, toward +∞+\infty and toward −∞-\infty.

Comparison. For non-negative finite numbers, comparing the 32-bit patterns as unsigned integers gives the same order as comparing the numbers (this is the reason the exponent is biased and placed before the fraction). +0=−0+0 = -0. Any comparison with a NaN is false except "not equal", so x≠xx \ne x is true for a NaN.

Exceptions. Invalid operation (result NaN), division by zero (result ±∞\pm\infty), overflow (result ±∞\pm\infty or the largest finite number, depending on rounding mode), underflow, and inexact (the rounded result differs from the exact one).

Encoding a number by hand.

  1. Convert the absolute value to binary, including the fraction.
  2. Normalise to 1.xxx×2k1.xxx \times 2^{k} by shifting the point; kk is the true exponent.
  3. e=k+biase = k + \text{bias}, written in EE bits. The sign bit is 1 for a negative number.
  4. The fraction field is the bits after the leading 1, padded with zeros on the right to MM bits. If there are more than MM bits, round (ties to even).

Decoding. Split the pattern into fields, check ee for the special cases, then apply the formula.

How it works

Step through eight real patterns. For each, the sign, exponent and fraction fields are shown as bit cells, with the fields' integer values and the whole word. The words are packed by the platform's own IEEE 754 routines, not typed in.

IEEE 754 single precision, field by field: The number 1.0

Computed exactly, not typed

Working

1.0 = 1.0 x 2^0
stored exponent = 0 + 127 = 127 = 0111 1111
fraction = 0 (the leading 1 is implied)

Value, format and bits (changed bits in amber)

sign (1 bit)unsigned= 0
0
exponent field (8 bits)biased by 127= 127
01111111
fraction field (23 bits)unsigned= 0
00000000
00000000
0000000
whole word, valuefloat, normal: 1.fraction x 2^(127 - 127) = 2^0= 1
00111111
10000000
00000000
00000000

Step 1

A normal number is written 1.f x 2^e. The leading 1 is not stored (the hidden bit), only the fraction f after the binary point. The exponent field stores e + 127, so the exponent 0 is stored as 127.

1 / 9
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. Python 3.15.1, darwin arm64. python3 scripts/gen-dl-traces.py

To see how a pattern is built, step through the hand method for −118.625-118.625 and then the rounding of 0.10.1. The last step of the first animation is compared with the platform's own float packing.

Encoding a float by hand, step by step: Step 1: the sign

Computed exactly, not typed

Working

-118.625 is negative
sign bit = 1, then work with 118.625

Value, format and bits (changed bits in amber)

sign bitunsigned= 1
1

Step 1

The sign is stored on its own. The remaining steps use the absolute value.

1 / 7
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. Python 3.15.1, darwin arm64. python3 scripts/gen-dl-traces.py

Notice three things as you step: the denormal has an all-zero exponent field, while infinity and NaN have an all-ones one; the fraction of 0.10.1 ends in 1101 because the infinite tail 0011... was rounded up; and 2242^{24} has an all-zero fraction (it is a power of two), yet its neighbour above is 224+22^{24} + 2, so 224+12^{24} + 1 cannot be stored.

Worked examples

EX 1Decode the pattern 0x40490FDB

Easy
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <float.h>
 
static uint32_t bits_of(float x) {
    uint32_t u;
    memcpy(&u, &x, sizeof u);
    return u;
}
 
static float float_of(uint32_t u) {
    float x;
    memcpy(&x, &u, sizeof x);
    return x;
}
 
static void fields(uint32_t u) {
    printf("%08X: sign %u, exponent %u, fraction %u (0x%06X)\n", u, u >> 31, (u >> 23) & 0xFF, u & 0x7FFFFF, u & 0x7FFFFF);
}
 
int main(void) {
    uint32_t pi = 0x40490FDB;
    fields(pi);
    printf("value %.9g\n", float_of(pi));
    printf("-118.625 is %08X\n", bits_of(-118.625f));
    printf("0.1f is %08X = %.27f\n", bits_of(0.1f), (double)0.1f);
    printf("smallest denormal %.9g, FLT_MIN %.9g, FLT_MAX %.9g\n", float_of(1), FLT_MIN, FLT_MAX);
    volatile float big = 16777216.0f;
    float next = big + 1.0f;
    printf("2^24 + 1 == 2^24 in float: %d\n", next == big);
    double s = 0.1 + 0.2;
    printf("0.1 + 0.2 == 0.3 in double: %d, sum %.17g\n", s == 0.3, s);
    return 0;
}

Output:

40490FDB: sign 0, exponent 128, fraction 4788187 (0x490FDB)
value 3.14159274
-118.625 is C2ED4000
0.1f is 3DCCCCCD = 0.100000001490116119384765625
smallest denormal 1.40129846e-45, FLT_MIN 1.17549435e-38, FLT_MAX 3.40282347e+38
2^24 + 1 == 2^24 in float: 1
0.1 + 0.2 == 0.3 in double: 0, sum 0.30000000000000004

Step 1. 0x40490FDB=0100 0000 0100 1001 0000 1111 1101 10110x40490FDB = 0100\,0000\,0100\,1001\,0000\,1111\,1101\,1011. The sign bit is 0. The next 8 bits are 1000 0000=1281000\,0000 = 128, so the true exponent is 128−127=1128 - 127 = 1.

Step 2. The fraction field is 100 1001 0000 1111 1101 1011=4788187100\,1001\,0000\,1111\,1101\,1011 = 4788187 (hex 490FDB). The significand is 1+4788187/223=1.57079641 + 4788187 / 2^{23} = 1.5707964.

Step 3. Value =1.5707964×21=3.1415927= 1.5707964 \times 2^1 = 3.1415927, which is π\pi as a single-precision number (the program prints 3.14159274).

EX 2Encode -118.625 in single precision

Easy

Step 1. 118=11101102118 = 1110110_2 and 0.625=0.10120.625 = 0.101_2, so 118.625=1110110.1012118.625 = 1110110.101_2.

Step 2. Normalise: 1.110110101×261.110110101 \times 2^6. The true exponent is 6.

Step 3. Biased exponent 6+127=133=1000 01016 + 127 = 133 = 1000\,0101. Sign bit 1.

Step 4. Fraction field: the bits after the leading 1 are 110110101, padded with zeros to 23 bits: 110 1101 0100 0000 0000 0000110\,1101\,0100\,0000\,0000\,0000.

Result. 1 10000101 11011010100000000000000=1100 0010 1110 1101 0100 0000 0000 0000=1\ 10000101\ 11011010100000000000000 = 1100\,0010\,1110\,1101\,0100\,0000\,0000\,0000 = C2ED4000. The program confirms it (line 2 of its output), and the animation shows the same fields. No rounding was needed, because 118.625 is a sum of powers of two with at most 24 significant bits.

EX 30.1 is rounded, and what is actually stored

Medium

Step 1. 0.1=0.00011‾2=1.1001‾…×2−40.1 = 0.0\overline{0011}_2 = 1.\overline{1001}\ldots \times 2^{-4}, an infinite fraction (see number systems).

Step 2. The biased exponent is −4+127=123=0111 1011-4 + 127 = 123 = 0111\,1011.

Step 3. The 23 fraction bits are 1001 1001 1001 1001 1001 100, followed by the tail 1100... which is more than half a unit in the last place, so the last bit is rounded up: the field ends 101 instead of 100.

Result. The pattern is 3DCCCCCD, and the exact value stored is 0.1000000014901161193847656250.100000001490116119384765625, a little more than 0.1 (the program prints the exact digits). The relative error is under 2−242^{-24}.

EX 4Limits and denormals

Medium

From the program output: the smallest positive denormal is 1.40129846×10−45=2−1491.40129846 \times 10^{-45} = 2^{-149}, the smallest normal is FLT_MIN =1.17549435×10−38=2−126= 1.17549435 \times 10^{-38} = 2^{-126}, and the largest finite is FLT_MAX =3.40282347×1038= 3.40282347 \times 10^{38}.

Why 149? A denormal is 0.f×2−1260.f \times 2^{-126}, and the smallest non-zero fraction is 2−232^{-23}, so the smallest denormal is 2−23×2−126=2−1492^{-23} \times 2^{-126} = 2^{-149}.

Why is the largest exponent field 254, not 255? Field value 255 is reserved for infinity and NaN, so the largest normal true exponent is 254−127=127254 - 127 = 127. With the largest fraction (all ones) the significand is 2−2−232 - 2^{-23}, giving (2−2−23) 2127(2 - 2^{-23})\,2^{127}.

EX 5Rounding surprises

GATE level

The program shows two facts. First, in single precision 224+12^{24} + 1 rounds back to 2242^{24}: above 2242^{24} the spacing is 2, so odd integers are not representable, and ties go to the even neighbour. Counting up by adding 1.0f to a float gets stuck at 16777216. Second, in double precision 0.1+0.2=0.300000000000000040.1 + 0.2 = 0.30000000000000004, which is not equal to 0.30.3, so 0.1 + 0.2 == 0.3 is false. Never test floating-point numbers for exact equality unless they are exactly representable (such as small integers and sums of powers of two).

EX 6A custom format: 1 sign, 4 exponent (bias 7), 3 fraction bits

GATE level

Take an 8-bit format built on the same rules as IEEE 754: hidden bit, bias 7, exponent field 0 for zero and denormals and 15 for infinity and NaN.

Largest finite. Exponent field 1414, true exponent 14−7=714 - 7 = 7, fraction all ones: (2−2−3)×27=1.875×128=240(2 - 2^{-3}) \times 2^7 = 1.875 \times 128 = 240.

Smallest normal. Exponent field 1, fraction 0: 21−7=2−6=1/642^{1 - 7} = 2^{-6} = 1/64.

Smallest positive denormal. 2−3×2−6=2−9=1/5122^{-3} \times 2^{-6} = 2^{-9} = 1/512.

Count of patterns. Normal: 1414 exponent values × 8\times\ 8 fractions × 2\times\ 2 signs =224= 224. Denormal: 77 non-zero fractions × 2=14\times\ 2 = 14. Zero: 2. Infinity: 2. NaN: 2×7=142 \times 7 = 14. Total 224+14+2+2+14=256224 + 14 + 2 + 2 + 14 = 256, which equals 282^8 as it must. There are 224+14+2−1=239224 + 14 + 2 - 1 = 239 distinct finite values, since +0=−0+0 = -0.

Machine epsilon. Spacing just above 1 is 2−3=0.1252^{-3} = 0.125.

EX 7Comparing two floats by their bit patterns

GATE level

For positive floats, the pattern order is the numeric order. So 0x400000000x40000000 (2.02.0) is below 0x40490FDB0x40490FDB (3.141592743.14159274), as the integers 1073741824<10785300111073741824 < 1078530011 say. For negative floats the order of the patterns, read as unsigned integers, is reversed, because of the sign-magnitude form; hardware therefore compares the sign first.

Cheat box

Cheat box

  • Single: 1+8+231 + 8 + 23, bias 127. Double: 1+11+521 + 11 + 52, bias 1023.
  • Normal (0<e<max⁡0 < e < \max): (−1)s(1.f)2×2e−bias(-1)^s (1.f)_2 \times 2^{e - \text{bias}}.
  • Denormal (e=0e = 0, f≠0f \ne 0): (−1)s(0.f)2×21−bias(-1)^s (0.f)_2 \times 2^{1 - \text{bias}}. Zero: e=0e = 0, f=0f = 0.
  • ee all ones: infinity (f=0f = 0), NaN (f≠0f \ne 0).
  • Largest finite single: (2−2−23)2127≈3.4×1038(2 - 2^{-23}) 2^{127} \approx 3.4 \times 10^{38}. Smallest normal: 2−1262^{-126}. Smallest denormal: 2−1492^{-149}.
  • Double: largest ≈1.8×10308\approx 1.8 \times 10^{308}, smallest normal 2−10222^{-1022}, smallest denormal 2−10742^{-1074}.
  • Precision: 24 bits (about 7 decimal digits) single, 53 bits (about 16) double. Integers exact up to 2242^{24} and 2532^{53}.
  • Spacing in [2k,2k+1)[2^k, 2^{k+1}) is 2k−M2^{k - M}.
  • Rounding: nearest, ties to even. NaN is unequal to everything including itself. +0=−0+0 = -0.
  • Encode: binary, normalise, add bias, drop the leading 1, pad or round.

Traps and GATE patterns

Connections

Floating-point addition, multiplication and the effect of rounding are in floating-point arithmetic. The exponent is an excess code as in signed number representation, and the contrast with a fixed position of the point is in fixed-point arithmetic. In C, float and double use these formats, and (int) conversions truncate toward zero as in C types and operators.

PYQs

3 previous year questions from your book. I re-solved each one myself (3 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2026 · Set 1 · MCQ · 1 markQ1 · page 153 of the book
Consider the real valued variables X, Y and Z
represented using the IEEE -754 single precision
floating-point format. The binary representations
of X and Y in hexadecimal notation are as
follows:

X: 35C00000
Y: 34A00000

Let Z = X + Y.

Which one of the following is the binary
representation of Z, in hexadecimal notation?
  • (a)35C80000
  • (b)35CD0000
  • (c)35E80000
  • (d)35EC0000
GATE 2026 · Set 2 · NATQ4 · page 153 of the book
The 32-bit IEEE 754 single precision
representation of a number is 0XC2710000.
The number in decimal representation is
________ (rounded off to two decimal places).
GATE 2022 · MCQQ10 · page 154 of the book
Consider three floating point numbers A, B and C
stored in registers RA, RB and RC, respectively as
per IEEE-754 single precision floating point
format. The 32-bit content stored in these registers
(in hexadecimal form) are as follows.

RA = 0xC1400000     RB = 0x42100000

RC = 0x41400000

Which one of the following is FALSE?
  • (a)A + C = 0
  • (b)C = A + B
  • (c)B = 3C
  • (d)(B - C) > 0

Self-check

Question 1

What is the single-precision pattern for 1.01.0 and for −2.0-2.0?

Show answer

1.0=1.0×201.0 = 1.0 \times 2^0: sign 0, exponent 0+127=127=0111 11110 + 127 = 127 = 0111\,1111, fraction 0, so 0x3F8000000x3F800000. −2.0=−1.0×21-2.0 = -1.0 \times 2^1: sign 1, exponent 128=1000 0000128 = 1000\,0000, fraction 0, so 0xC00000000xC0000000.

Question 2

What number has the single-precision pattern 0x000000000x00000000, 0x800000000x80000000, 0x7F8000000x7F800000 and 0xFFC000000xFFC00000?

Show answer

+0+0, −0-0, +∞+\infty, and a (negative-signed, quiet) NaN: the last has exponent all ones and a non-zero fraction.

Question 3

How many distinct single-precision NaN bit patterns exist?

Show answer

Exponent all ones, fraction non-zero: 223−12^{23} - 1 fractions, times 2 signs, =224−2=16777214= 2^{24} - 2 = 16777214.

Question 4

A floating-point format has 1 sign bit, 5 exponent bits (bias 15) and 10 fraction bits, with a hidden bit and IEEE-style special values. What is the largest finite value?

Show answer

The largest normal exponent field is 25−2=302^5 - 2 = 30, so the true exponent is 30−15=1530 - 15 = 15. The significand is 2−2−102 - 2^{-10}. The value is (2−2−10)×215=65504(2 - 2^{-10}) \times 2^{15} = 65504.

Revision card

One-screen revision

  • Single 1+8+231+8+23 bias 127; double 1+11+521+11+52 bias 1023.
  • Normal: (−1)s 1.f×2e−bias(-1)^s\,1.f \times 2^{e-\text{bias}}. Denormal (e=0e=0): 0.f×21−bias0.f \times 2^{1-\text{bias}}. ee all ones: infinity or NaN.
  • Largest single ≈3.4×1038\approx 3.4 \times 10^{38}, smallest normal 2−1262^{-126}, smallest denormal 2−1492^{-149}.
  • Hidden bit gives 24 (53) bits of precision. Integers exact up to 2242^{24} (2532^{53}).
  • Spacing in [2k,2k+1)[2^k, 2^{k+1}) is 2k−M2^{k-M}; rounding is nearest-even.
  • Encode: binary, normalise, add bias, drop leading 1. Check custom-format rules in the question.

References

  • ·IEEE Std 754-2008 (and 754-1985), Standard for Floating-Point Arithmetic, formats and encodings (binary32 and binary64)
  • ·Hamacher, Vranesic, Zaky, Computer Organization, 5th ed., Chapter 6 Arithmetic (floating-point numbers and operations)
  • ·Patterson and Hennessy, Computer Organization and Design, Chapter 3 Arithmetic for Computers (floating point)

Verification

The animation patterns are packed by Python's struct module (the platform's own IEEE 754 binary32) and re-decoded in tests/dl-traces.test.ts. The decoding formula is checked in scripts/enum-checks/dl_numbers.py against the hardware decode for every exponent field and 300000 random patterns, with the ordering property, spacing, denormal limits, NaN count, and a toy 8-bit format brute-forced. C programs are compiled and run by npm run verify:c. Which format a GATE question means (hidden bit, bias, whether denormals exist) is not checked against any PYQ yet; textbook chapter titles are from memory. The independent second pass has not been run yet, so the page stays draft. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (conversions, signed ranges and flags, IEEE 754 fields and custom formats, Boolean identities and counts, K-map groups, adder carries, BCD correction, flip-flop conversions, counter sequences and T equations, state reduction, Quine-McCluskey rounds and covers, floating-point alignment and rounding); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never