A value and its printed form
#include <stdio.h> int main(void) { double x = -0.15625; printf("%g\n", x); } This prints -0.15625. The decimal output is readable, but it does not show how the value is represented: -0.15625 is also -5/32, a fraction with a power of two in its denominator. section 5.7.7 section 8.3.4
A floating-point value can be understood through a sign, a finite sequence of binary significand bits, and an exponent that scales those bits by a power of two. For the example, sign -1, exponent -2, and significand bits 101 give -(1/2 + 1/8) × 2^-2 = -5/32. The position at which the binary expansion is cut off depends on the number’s magnitude; it “floats.” section 5.7.7
TAKEAWAY: Floating-point arithmetic approximates real-number arithmetic. A type has a restricted range and a limited number of significand bits, so a value or an intermediate result may be cut off. Unlike integer computation without overflow, a floating-point computation need not produce an exact mathematical result. section 5.7.7 section 5.8
Keep three distinctions in view:
- C has real floating-point types float, double, and long double, as well as corresponding complex floating-point types. A type’s precision is not the accuracy of a particular computation. section 5.2
- The float.h macros DBL_MANT_DIG, DBL_MIN_EXP, and DBL_MAX_EXP describe properties of double. DBL_MIN and DBL_MAX describe bounds; DBL_MIN is not the most negative value. section 5.7.7
- Binary representation is a model for determining operations, not necessarily a description of how an object is stored. The C standard does not completely fix the precision of every double operation across platforms. section 5.1.3
- For decimal output without special requirements, use %g. Match printf format specifiers and modifiers to their arguments: an inappropriate one makes behavior undefined. section 8.3.4



















