5.2.4.2.2 Characteristics of floating types <float.h>

1

The characteristics of floating types are defined in terms of a model that describes a representation of floating-point numbers and values that provide information about an implementation’s floating-point arithmetic.[1] The following parameters are used to define the model for each floating-point type:

s

sign (\pm 1)

b

base or radix of exponent representation (an integer > 1)

e

exponent (an integer between a minimum e_{\text{min}} and a maximum e_{\text{max}})

p

precision (the number of base-b digits in the significand)

f_k

nonnegative integers less than b (the significand digits)

2

A floating-point number (x) is defined by the following model:

x = sb^e \sum\limits^p_{k=1} f_kb^{-k},\ e_\text{min} \le e \le e_\text{max}

3

In addition to normalized floating-point numbers (f_1 > 0\ \text{if}\ x \not= 0), floating types may be able to contain other kinds of floating-point numbers, such as subnormal floating-point numbers (x \not= 0, e = e_\text{min}, f_1 = 0) and unnormalized floating-point numbers (x \not= 0, e > e_\text{min}, f_1 = 0), and values that are not floating-point numbers, such as infinities and NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates through almost every arithmetic operation without raising a floating-point exception; a signaling NaN generally raises a floating-point exception when occurring as an arithmetic operand.[2]

4

An implementation may give zero and non-numeric values (such as infinities and NaNs) a sign or may leave them unsigned. Wherever such values are unsigned, any requirement in this International Standard to retrieve the sign shall produce an unspecified sign, and any requirement to set the sign shall be ignored.

5

The accuracy of the floating-point operations (+, -, *, /) and of the library functions in <math.h> and <complex.h> that return floating-point results is implementation- defined, as is the accuracy of the conversion between floating-point internal representations and string representations performed by the library functions in <stdio.h>, <stdlib.h>, and <wchar.h>. The implementation may state that the accuracy is unknown.

6

All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessing directives; all floating values shall be constant expressions. All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX, and FLT_ROUNDS have separate names for all three floating-point types. The floating-point model representation is provided for all values except FLT_EVAL_METHOD and FLT_ROUNDS.

7

The rounding mode for floating-point addition is characterized by the implementation- defined value of FLT_ROUNDS:[3]

-1

indeterminable

0

toward zero

1

to nearest

2

toward positive infinity

3

toward negative infinity

All other values for FLT_ROUNDS characterize implementation-defined rounding behavior.

8

Except for assignment and cast (which remove all extra range and precision), the values of operations with floating operands and values subject to the usual arithmetic conversions and of floating constants are evaluated to a format whose range and precision may be greater than required by the type. The use of evaluation formats is characterized by the implementation-defined value of FLT_EVAL_METHOD:[4]

-1

indeterminable;

0

evaluate all operations and constants just to the range and precision of the type;

1

evaluate operations and constants of type float and double to the range and precision of the double type, evaluate long double operations and constants to the range and precision of the long double type;

2

evaluate all operations and constants to the range and precision of the long double type.

All other negative values for FLT_EVAL_METHOD characterize implementation-defined behavior.

9

The values given in the following list shall be replaced by constant expressions with implementation-defined values that are greater or equal in magnitude (absolute value) to those shown, with the same sign:

  • radix of exponent representation, b

Identifier

Value

FLT_RADIX

2

  • number of base-FLT_RADIX digits in the floating-point significand, p

Identifier

FLT_MANT_DIG

DBL_MANT_DIG

LDBL_MANT_DIG

  • number of decimal digits, n, such that any floating-point number in the widest supported floating type with p_\text{max} radix b digits can be rounded to a floating-point number with n decimal digits and back again without change to the value,

\begin{cases}
p_\text{max}\log_{10} b & \text{if}\ b\ \text{is a power of}\ 10\\
\lceil 1 + p_\text{max} \log_{10} b \rceil & \text{otherwise}
\end{cases}

Identifier

Value

DECIMAL_DIG

10

  • number of decimal digits, q, such that any floating-point number with q decimal digits can be rounded into a floating-point number with p radix b digits and back again without change to the q decimal digits,

\begin{cases}
p_\text{max}\log_{10} b & \text{if}\ b\ \text{is a power of}\ 10\\
\lfloor (p-1) \log_{10} b \rfloor & \text{otherwise}
\end{cases}

Identifier

Value

FLT_DIG

6

DBL_DIG

10

LDBL_DIG

10

  • minimum negative integer such that FLT_RADIX raised to one less than that power is a normalized floating-point number, e_\text{min}

Identifier

FLT_MIN_EXP

DBL_MIN_EXP

LDBL_MIN_EXP

  • minimum negative integer such that 10 raised to that power is in the range of normalized floating-point numbers, \left\lceil\log_{10}b^{e_\text{min}-1}\right\rceil

Identifier

Value

FLT_MIN_10_EXP

-37

DBL_MIN_10_EXP

-37

LDBL_MIN_10_EXP

-37

  • maximum integer such that FLT_RADIX raised to one less than that power is a representable finite floating-point number, e_\text{max}

Identifier

FLT_MAX_EXP

DBL_MAX_EXP

LDBL_MAX_EXP

  • maximum integer such that 10 raised to that power is in the range of representable finite floating-point numbers, \left\lfloor\log_{10}((1-b^{-p})b^{e_\text{max}}\right\rfloor

Identifier

Value

FLT_MAX_10_EXP

+37

DBL_MAX_10_EXP

+37

LDBL_MAX_10_EXP

+37

10

The values given in the following list shall be replaced by constant expressions with implementation-defined values that are greater than or equal to those shown:

  • maximum representable finite floating-point number, (1-b^{-p})b^{e_\text{max}}

Identifier

Value

FLT_MAX

1E+37

DBL_MAX

1E+37

LDBL_MAX

1E+37

11

The values given in the following list shall be replaced by constant expressions with implementation-defined (positive) values that are less than or equal to those shown:

  • the difference between 1 and the least value greater than 1 that is representable in the given floating point type, b^{1-p}

Identifier

Value

FLT_EPSILON

1E-5

DBL_EPSILON

1E-9

LDBL_EPSILON

1E-9

  • minimum normalized positive floating-point number, b^{e_\text{min}-1}

Identifier

Value

FLT_MIN

1E-37

DBL_MIN

1E-37

LDBL_MIN

1E-37

Recommended practice

12

Conversion from (at least) double to decimal with DECIMAL_DIG digits and back should be the identity function.

13

EXAMPLE 1 The following describes an artificial floating-point representation that meets the minimum requirements of this International Standard, and the appropriate values in a <float.h> header for type float:

x = s16^e \sum\limits_{k=1}^6 f_k 16^{-k},\ -31 \le e \le +32

Identifier

Value

FLT_RADIX

16

FLT_MANT_DIG

6

FLT_EPSILON

9.53674316E-07F

FLT_DIG

6

FLT_MIN_EXP

-31

FLT_MIN

2.93873588E-39F

FLT_MIN_10_EXP

-38

FLT_MAX_EXP

+32

FLT_MAX

3.40282347E+38F

FLT_MAX_10_EXP

+38

14

EXAMPLE 2 The following describes floating-point representations that also meet the requirements for single-precision and double-precision normalized numbers in IEC 60559,[5] and the appropriate values in a <float.h> header for types float and double:

x_f = s2^e \sum\limits_{k=1}^{24} f_k 2^{-k},\ -125 \le e \le +128

x_d = s2^e \sum\limits_{k=1}^{53} f_k 2^{-k},\ -1021 \le e \le +1024

Identifier - Value - Comment

FLT_RADIX

2

DECIMAL_DIG

17

FLT_MANT_DIG

24

FLT_EPSILON

1.19209290E-07F

decimal constant

FLT_EPSILON

0X1P-23F

hex constant

FLT_DIG

6

FLT_MIN_EXP

-125

FLT_MIN

1.17549435E-38F

decimal constant

FLT_MIN

0X1P-126F

hex constant

FLT_MIN_10_EXP

-37

FLT_MAX_EXP

+128

FLT_MAX

3.40282347E+38F

decimal constant

FLT_MAX

0X1.fffffeP127F

hex constant

FLT_MAX_10_EXP

+38

DBL_MANT_DIG

53

DBL_EPSILON

2.2204460492503131E-16

decimal constant

DBL_EPSILON

0X1P-52

hex constant

DBL_DIG

15

DBL_MIN_EXP

-1021

DBL_MIN

2.2250738585072014E-308

decimal constant

DBL_MIN

0X1P-1022

hex constant

DBL_MIN_10_EXP

-307

DBL_MAX_EXP

+1024

DBL_MAX

1.7976931348623157E+308

decimal constant

DBL_MAX

0X1.fffffffffffffP1023

hex constant

DBL_MAX_10_EXP

+308

If a type wider than double were supported, then DECIMAL_DIG would be greater than 17. For example, if the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of precision), then DECIMAL_DIG would be 21.

Forward References

Footnotes