liveBook · Manning

Floating-point constant

As explained in Modern C

A floating-point constant is a C literal that represents a floating-point value and has type float, double, or long double according to its notation and suffix.

A floating-point constant is a C literal representing a floating-point value. Its notation may use a decimal point or exponent, and its suffix selects float, double, or long double. section 5.3

Three types, two notations

The literals 0.2F, 0.2, and 0.2L have types float, double, and long double. The hexadecimal forms 0x1.99999AP-3F, 0x1.999999999999AP-3, and 0xC.CCCCCCCCCCCCCCDP-6L express corresponding floating-point values with the same suffix pattern.

Read floating-point constants by separating notation from surrounding operators:

  • A leading minus is the negation operator, not part of the numerical literal; the minus sign in an exponent is part of the floating-point notation. section 5.3

How Modern C covers it

How deep it goes
Explains decimal, scientific, hexadecimal, suffix, and negation rules, but does not develop floating-point representation internals.
Examples
Uses 1.7E-13, 0x1.7aP-13, 0.2F, 0.2, and 0.2L as decimal and hexadecimal examples.
What you can do after
Evaluate floating-point literal notation and identify the type selected by its suffix.
How it connects
Connects numerical literals with literal types, suffixes, negation, and hexadecimal floating-point constants.

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.