ISO C99 defines macros that let you determine what sort of floating-point number a variable holds.
int
. The possible values are:
FP_NAN
FP_INFINITE
FP_ZERO
FP_SUBNORMAL
fpclassify
returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify
is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify
, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE)
isfinite
is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL)
(fpclassify (x) == FP_NAN)
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1
if x represents negative infinity,
1
if x represents positive infinity, and 0
otherwise.
Note: The isnan
macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x)
EDOM
or ERANGE
; infnan
returns the
value that a math function would return if it set errno
to that
value. See section Error Reporting by Mathematical Functions. -ERANGE
is also acceptable
as an argument, and corresponds to -HUGE_VAL
as a value.
In the BSD library, on certain machines, infnan
raises a fatal
signal in all cases. The GNU library does not do likewise, because that
does not fit the ISO C specification.
Portability Note: The functions listed in this section are BSD extensions.
Go to the first, previous, next, last section, table of contents.