liveBook · Manning

Float64

As explained in Modern C, Third Edition

double is a C floating-point type providing at least the precision and range required for double-precision real-number calculations.

In C, double is a real floating-point base type. Floating-point types differ by precision, which determines the valid range of values; decimal floating-point literals such as 0.2 have type double by default. section 5.2 section 5.3

The value of 0.2

A declaration such as `double x = 0.2;` uses a double floating-point literal. The stored value may differ from the written decimal because binary fractional digits can be rounded or truncated; on one machine, 0.2 becomes approximately 0.2000000000000000111. section 5.3

Use these rules when reading or writing double values:

  • Treat a decimal floating-point literal's effective value as potentially different from its decimal spelling. section 5.3
  • Use hexadecimal floating-point notation when a literal should correspond more closely to a binary floating-point representation; such literals are less readable. section 5.3
float double long double
Literal 0.2F 0.2 0.2L
Value 0x1.9999’9AP-3F 0x1.9999’9999’9999AP-3 0xC.CCCC’ CCCC’ CCCC’ CCDP-6L

Compare the 0.2, 0.2F, and 0.2L spellings with their corresponding floating-point types and hexadecimal forms. section 5.3

How Modern C, Third Edition covers it

How deep it goes
Defines precision and approximation, then compares literal spellings, but stops short of detailing floating-point storage internals.
Examples
Uses 0.2, extended decimal spellings, and hexadecimal floating-point literals to demonstrate approximation and representation.
What you can do after
Evaluate/understand why double literals can have rounded effective values and how hexadecimal notation changes their spelling.
How it connects
Connects double with floating-point numbers, precision, range, arithmetic expressions, and floating-point literals.

Also explained in

Compare how 7 books explain float64 →

Related concepts

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