[Cfp-interest 2084] number classification macros, fpclassify and normal numbers

Vincent Lefevre vincent at vinc17.net
Tue Aug 3 19:34:53 PDT 2021


It seems that the classification macros introduced in 7.12p12 of C2x
N2596 (FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL and FP_ZERO) are
not explicitly defined. This may be obvious with the fpclassify
description in 7.12.3.1p2, but it seems that "normal" has not been
defined yet ("normalized" has been defined, but not "normal").

7.12.3.6p2 says "The isnormal macro determines whether its argument
value is normal (neither zero, subnormal, infinite, nor NaN)." but
this does not constitute a definition (it is not in italic), and
"neither zero, subnormal, infinite, nor NaN" excludes the possible
implementation-defined categories allowed for fpclassify.

Note that for a strict floating-point format, "normal" should be
the same as "normalized". But with values that are neither zero,
subnormal, infinite, NaN, nor normalized, which may occur with the
double-double format (conventional "long double" type on PowerPC),
the meaning is ambiguous. Should the standard add some requirement,
or should it make this implementation-defined?

GCC assumes the following definition in gcc/builtins.c:

        /* isnormal(x) -> isgreaterequal(fabs(x),DBL_MIN) &
           islessequal(fabs(x),DBL_MAX).  */

(for double; similar for the other types), where DBL_MIN is the
minimum *normalized* positive floating-point number and DBL_MAX
is the maximum representable finite number (see N2092[*]). Note:
N2596 says "maximum representable finite floating-point number",
but "floating-point" should be dropped to avoid ambiguity.

[*] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2092.htm

Thus for double-double, the only possibilities are zero, subnormal,
normal, infinite and NaN. And a value may be classified as a normal
number while not being a normalized floating-point number. Example:
1 + 2^(-200). It is not a normalized floating-point number because
it does not fit in LDBL_MANT_DIG = 106 bits (as defined by GCC on
PowerPC).

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list