Hexadecimal Floating-Point Literals and math.h Macros
- Updated2023-02-21
- 1 minute(s) read
Hexadecimal Floating-Point Literals and math.h Macros
Per the C99 specification, you can express floating-point numbers in hexadecimal format. Hexadecimal floating-point literals follow the following syntax:
0xA.BpCf
0x—Prefix
A—Hexidecimal digits that represent the whole number part of the sigificand
.—Optional decimal
B—Hexidecimal digits that represent the fractional part of the significand
pC—Positive or negative decimal integer that represents the power of two by which the significand is multiplied
f—Optional suffix, f or F, that designates the value as a float. If you do not designate f or F, the default value is double.
Example Code
0xDEADBEEFp-5
0x9.00Ap10f // the 'f' suffix specifies a float
0x.1p33
0x1.p32 // the syntax allows the decimal even if there is no fractional part
math.h C99 Macros
If C99 extensions are enabled, you can use the following related macros defined in math.h:
- HUGE_VAL—A constant double representation of positive infinity
- HUGE_VALF—A constant float representation of positive infinity
- INFINITY—A constant float representation of positive infinity
- NAN—A constant float representation of (quiet) NaN
- FP_INFINITE—Numerical classification specifying an infinite floating-point value
- FP_NAN—Numerical classification specifying a floating-point value that is not a number
- FP_NORMAL—Numerical classification specifying a normal floating-point value
- FP_SUBNORMAL—Numerical classification specifying a sumbnormal floating-point value
- FP_ZERO—Numerical classification specifying a floating-point value that represents 0