liveBook · Manning

Effective value

As explained in Modern C

An effective value is the value actually represented by a C floating-point constant after the implementation's rounding or truncation.

When 0.2 is not exactly 0.2

On one machine, the C constant `0.2` has the effective value `0.2000000000000000111`. Consequently, `0.2` and `0.2000000000000000111` can represent the same floating-point value. section 5.3

TAKEAWAY: The effective value of a decimal floating-point constant may differ from its literal value. Binary fractional digits cannot always represent the written decimal exactly, so the implementation truncates or rounds them. section 5.3

Hexadecimal floating-point constants more closely describe binary representations; on most modern architectures, constants with few enough digits correspond exactly to their literal values. section 5.3

 

float

double

long double

literal 0.2F 0.2 0.2L
value 0x1.99999AP-3F 0x1.999999999999AP-3 0xC.CCCCCCCCCCCCCCDP-6L

Compare decimal, hexadecimal, `float`, `double`, and `long double` spellings for the value commonly written as `0.2`. section 5.3

How Modern C covers it

How deep it goes
Defines implementation rounding and truncation, then contrasts decimal approximation with hexadecimal representation.
Examples
Uses `0.2`, its expanded effective value, and hexadecimal spellings such as `0x1.99999AP-3F`.
What you can do after
Evaluate why decimal and hexadecimal floating-point spellings can represent different or identical values.
How it connects
Connects literal value with decimal floating-point constants and hexadecimal floating-point constants.

Also explained in

Compare how 2 books explain effective value →

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.