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): . 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 (1 bit), biased exponent ( bits) and fraction ( bits).
| Format | Total | Bias | Hidden bit | ||
|---|---|---|---|---|---|
| single (binary32) | 32 | 8 | 23 | 127 | yes |
| double (binary64) | 64 | 11 | 52 | 1023 | yes |
Let be the unsigned value of the exponent field, the unsigned value of the fraction field read as an integer, and write the fraction as the binary fraction .
Normal numbers ():
The leading 1 is not stored. It is the hidden bit (implicit leading 1), so the significand has bits of precision (24 for single, 53 for double). The exponent field is biased (excess code): the true exponent is .
Zero (, ): and , two patterns that compare equal.
Denormal (subnormal) numbers (, ):
There is no hidden bit and the exponent is fixed at ( for single, for double). They fill the gap between zero and the smallest normal number (gradual underflow).
Infinity (, ): .
NaN, not a number (, ). There are NaN patterns. A NaN is the result of an invalid operation such as or .
Key values.
| single | double | |
|---|---|---|
| largest finite | ||
| smallest normal | ||
| smallest denormal | ||
| spacing just above 1 (machine epsilon) | ||
| decimal digits of precision | about 7.2 | about 15.95 |
Spacing. Within the numbers are evenly spaced apart. So the absolute gap doubles every time the exponent grows by one, while the relative gap stays between and . All integers up to (single) or (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 and toward .
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). . Any comparison with a NaN is false except "not equal", so is true for a NaN.
Exceptions. Invalid operation (result NaN), division by zero (result ), overflow (result 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.
- Convert the absolute value to binary, including the fraction.
- Normalise to by shifting the point; is the true exponent.
- , written in bits. The sign bit is 1 for a negative number.
- The fraction field is the bits after the leading 1, padded with zeros on the right to bits. If there are more than bits, round (ties to even).
Decoding. Split the pattern into fields, check 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 typedWorking
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)
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.
To see how a pattern is built, step through the hand method for and then the rounding of . 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 typedWorking
-118.625 is negative sign bit = 1, then work with 118.625
Value, format and bits (changed bits in amber)
Step 1
The sign is stored on its own. The remaining steps use the absolute value.
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 ends in 1101 because the infinite tail 0011... was rounded up; and has an all-zero fraction (it is a power of two), yet its neighbour above is , so 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.30000000000000004Step 1. . The sign bit is 0. The next 8 bits are , so the true exponent is .
Step 2. The fraction field is (hex 490FDB). The significand is .
Step 3. Value , which is as a single-precision number (the program prints 3.14159274).
EX 2Encode -118.625 in single precision
EasyStep 1. and , so .
Step 2. Normalise: . The true exponent is 6.
Step 3. Biased exponent . Sign bit 1.
Step 4. Fraction field: the bits after the leading 1 are 110110101, padded with zeros to 23 bits: .
Result. 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
MediumStep 1. , an infinite fraction (see number systems).
Step 2. The biased exponent is .
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 , a little more than 0.1 (the program prints the exact digits). The relative error is under .
EX 4Limits and denormals
MediumFrom the program output: the smallest positive denormal is , the smallest normal is FLT_MIN , and the largest finite is FLT_MAX .
Why 149? A denormal is , and the smallest non-zero fraction is , so the smallest denormal is .
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 . With the largest fraction (all ones) the significand is , giving .
EX 5Rounding surprises
GATE levelThe program shows two facts. First, in single precision rounds back to : above 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 , which is not equal to , 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 levelTake 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 , true exponent , fraction all ones: .
Smallest normal. Exponent field 1, fraction 0: .
Smallest positive denormal. .
Count of patterns. Normal: exponent values fractions signs . Denormal: non-zero fractions . Zero: 2. Infinity: 2. NaN: . Total , which equals as it must. There are distinct finite values, since .
Machine epsilon. Spacing just above 1 is .
EX 7Comparing two floats by their bit patterns
GATE levelFor positive floats, the pattern order is the numeric order. So () is below (), as the integers 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: , bias 127. Double: , bias 1023.
- Normal (): .
- Denormal (, ): . Zero: , .
- all ones: infinity (), NaN ().
- Largest finite single: . Smallest normal: . Smallest denormal: .
- Double: largest , smallest normal , smallest denormal .
- Precision: 24 bits (about 7 decimal digits) single, 53 bits (about 16) double. Integers exact up to and .
- Spacing in is .
- Rounding: nearest, ties to even. NaN is unequal to everything including itself. .
- Encode: binary, normalise, add bias, drop the leading 1, pad or round.
Traps and GATE patterns
Connections
Across subjects
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
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
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).
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 and for ?
Show answerHide
: sign 0, exponent , fraction 0, so . : sign 1, exponent , fraction 0, so .
Question 2
What number has the single-precision pattern , , and ?
Show answerHide
, , , 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 answerHide
Exponent all ones, fraction non-zero: fractions, times 2 signs, .
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 answerHide
The largest normal exponent field is , so the true exponent is . The significand is . The value is .
Revision card
One-screen revision
- Single bias 127; double bias 1023.
- Normal: . Denormal (): . all ones: infinity or NaN.
- Largest single , smallest normal , smallest denormal .
- Hidden bit gives 24 (53) bits of precision. Integers exact up to ().
- Spacing in is ; 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
My notes (saved in this browser)