liveBook · Manning

Decimal floating-point constant

As explained in Modern C

A decimal floating-point constant is a C floating-point literal written with decimal digits whose effective value may differ from its written mathematical value.

Consider the literals 0.2, 0.2F, and 0.2L. Each presents the same decimal fraction, but floating-point representation can make its effective value differ from the written value, and suffixes select different types. Without a suffix, a decimal floating-point constant has type double; f or F selects float, while l or L selects long double. TAKEAWAY: a literal has a value, a type, and a binary representation. section 5.3

Why 0.2 is not always exactly 0.2

On one machine, 0.2 has the effective value 0.2000000000000000111. Consequently, 0.2 and 0.2000000000000000111 can denote the same value. Decimal fractional digits may be rounded or truncated when represented in binary. section 5.3

How Modern C covers it

How deep it goes
Defines rounding, suffix-based types, and binary representation, while deferring detailed representation mechanics.
Examples
Uses 0.0, 0.2, exponent notation, suffix variants, and hexadecimal constants as concrete comparisons.
What you can do after
Evaluate how notation and suffixes affect a floating-point literal's effective value and type.
How it connects
Connects decimal floating-point constants with hexadecimal floating-point constants, floating-point types, and binary representation.

Also explained in

Compare how 2 books explain decimal floating-point constant →

Related concepts

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.