5.2.4.2.2 Characteristics of floating types

Previous Table of Contents

327 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.16)

328 The following parameters are used to define the model for each floating-point type:

329 s     sign (±1)

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

331 e     exponent (an integer between a minimum emin and a maximum emax)

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

333 fk     nonnegative integers less than b (the significand digits)

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

x = sbek=1p fkb-k,     emin ≤ e ≤ emax

335 In addition to normalized floating-point numbers (f1>0 if x≠0), floating types may be able to contain other kinds of floating-point numbers, such as subnormal floating-point numbers (x≠0, e=emin, f1=0) and unnormalized floating-point numbers (x≠0, e>emin, f1=0), and values that are not floating-point numbers, such as infinities and NaNs.

336 A NaN is an encoding signifying Not-a-Number.

337 A quiet NaN propagates through almost every arithmetic operation without raising a floating-point exception;

338 a signaling NaN generally raises a floating-point exception when occurring as an arithmetic operand.17)

339 An implementation may give zero and non-numeric values (such as infinities and NaNs) a sign or may leave them unsigned.

340 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.

341 15) See 6.2.5.

342 16) The floating-point model is intended to clarify the description of each floating-point characteristic and does not require the floating-point arithmetic of the implementation to be identical.

343 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 routine in <stdio.h>, <stdlib.h> and <wchar.h>.

344 The implementation may state that the accuracy is unknown.

345 All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessing directives;

346 all floating values shall be constant expressions.

347 All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX, and FLT_ROUNDS have separate names for all three floating-point types.

348 The floating-point model representation is provided for all values except FLT_EVAL_METHOD and FLT_ROUNDS.

349 The rounding mode for floating-point addition is characterized by the implementation-defined value of FLT_ROUNDS:18)

-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.

350 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.

351 The use of evaluation formats is characterized by the implementation-defined value of FLT_EVAL_METHOD:19)

352 -1     indeterminable;

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

354 17) IEC 60559:1989 specifies quiet and signaling NaNs.

355 For implementations that do not support IEC 60559:1989, the terms quiet NaN and signaling NaN are intended to apply to encodings with similar behavior.

356 18) Evaluation of FLT_ROUNDS correctly reflects any execution-time change of rounding mode through the function fesetround in <fenv.h>.

357 19) The evaluation method determines evaluation formats of expressions involving all floating types, not just real types.

358 For example, if FLT_EVAL_METHOD is 1, then the product of two float _Complex operands is represented in the double _Complex format, and its parts are evaluated to double.

359 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;

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

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

362 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:

363 —  radix of exponent representation, b

FLT_RADIX                        2

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

FLT_MANT_DIG
DBL_MANT_DIG
LDBL_MANT_DIG

365 —  number of decimal digits, n, such that any floating-point number in the widest supported floating type with pmax radix b digits can be rounded to a floating-point number with n decimal digits and back again without change to the value,

pmaxlog10b              if b is a power of 10
⌈1+pmaxlog10b⌉      otherwise

DECIMAL_DIG                     10

366 —  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,

pmaxlog10b            if b is a power of 10
⌊(p-1)log10b⌋       otherwise

FLT_DIG                          6
DBL_DIG                         10
LDBL_DIG                        10

367 —  minimum negative integer such that FLT_RADIX raised to one less than that power is a normalized floating-point number, emin

FLT_MIN_EXP
DBL_MIN_EXP
LDBL_MIN_EXP

368 —  minimum negative integer such that 10 raised to that power is in the range of normalized floating-point numbers, ⌈log10 bemin-1

FLT_MIN_10_EXP                 -37
DBL_MIN_10_EXP                 -37
LDBL_MIN_10_EXP                -37

369 —  maximum integer such that FLT_RADIX raised to one less than that power is a representable finite floating-point number, emax

FLT_MAX_EXP
DBL_MAX_EXP
LDBL_MAX_EXP

370 —  maximum integer such that 10 raised to that power is in the range of representable finite floating-point numbers, ⌊log10((1 - b-p) bemax)⌋

FLT_MAX_10_EXP                 +37
DBL_MAX_10_EXP                 +37
LDBL_MAX_10_EXP                +37

371 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:

372 —  maximum representable finite floating-point number, (1-b-p)bemax

FLT_MAX                      1E+37
DBL_MAX                      1E+37
LDBL_MAX                     1E+37

373 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:

374 —  the difference between 1 and the least value greater than 1 that is representable in the given floating point type, b1-p

FLT_EPSILON                   1E-5
DBL_EPSILON                   1E-9
LDBL_EPSILON                  1E-9

375 —  minimum normalized positive floating-point number, bemin-1

FLT_MIN                      1E-37
DBL_MIN                      1E-37
LDBL_MIN                     1E-37

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

377 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 = s16ek=16 fk16-k,    -31 ≤ e ≤ +32

        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

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

xf = s2ek=124 fk2-k,    -125 ≤ e ≤ +128

xd = s2ek=153 fk2-k,    -1021 ≤ e ≤ +1024

        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.

379 20) The floating-point model in that standard sums powers of b from zero, so the values of the exponent limits are one less than shown here.

380 Forward references: conditional inclusion (6.10.1), complex arithmetic <complex.h> (7.3), extended multibyte and wide character utilities <wchar.h> (7.24), floating-point environment <fenv.h> (7.6), general utilities <stdlib.h> (7.20), input/output <stdio.h> (7.19), mathematics <math.h> (7.12).

Next

Created at: 2005-06-29 02:18:54 The text from WG14/N1124 is copyright © ISO