2 /* @(#)s_isnan.c 5.1 93/09/24 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
16 <<fpclassify>>, <<isfinite>>, <<isinf>>, <<isnan>>, and <<isnormal>>---floating-point classification macros; <<finite>>, <<finitef>>, <<isinf>>, <<isinff>>, <<isnan>>, <<isnanf>>---test for exceptional numbers
47 [C99 standard macros:]
49 int fpclassify(real-floating <[x]>);
50 int isfinite(real-floating <[x]>);
51 int isinf(real-floating <[x]>);
52 int isnan(real-floating <[x]>);
53 int isnormal(real-floating <[x]>);
55 [Archaic SUSv2 functions:]
57 int isnan(double <[arg]>);
58 int isinf(double <[arg]>);
59 int finite(double <[arg]>);
60 int isnanf(float <[arg]>);
61 int isinff(float <[arg]>);
62 int finitef(float <[arg]>);
65 <<fpclassify>>, <<isfinite>>, <<isinf>>, <<isnan>>, and <<isnormal>> are macros
66 defined for use in classifying floating-point numbers. This is a help because
67 of special "values" like NaN and infinities. In the synopses shown,
68 "real-floating" indicates that the argument is an expression of real floating
69 type. These function-like macros are C99 and POSIX-compliant, and should be
70 used instead of the now-archaic SUSv2 functions.
72 The <<fpclassify>> macro classifies its argument value as NaN, infinite, normal,
73 subnormal, zero, or into another implementation-defined category. First, an
74 argument represented in a format wider than its semantic type is converted to
75 its semantic type. Then classification is based on the type of the argument.
76 The <<fpclassify>> macro returns the value of the number classification macro
77 appropriate to the value of its argument:
81 <[x]> is either plus or minus infinity;
83 <[x]> is "Not A Number" (plus or minus);
85 <[x]> is a "normal" number (i.e. is none of the other special forms);
87 <[x]> is too small be stored as a regular normalized number (i.e. loss of precision is likely); or
89 <[x]> is 0 (either plus or minus).
92 The "<<is>>" set of macros provide a useful set of shorthand ways for
93 classifying floating-point numbers, providing the following equivalent
98 returns non-zero if <[x]> is finite. (It is equivalent to
99 (<<fpclassify>>(<[x]>) != FP_INFINITE && <<fpclassify>>(<[x]>) != FP_NAN).)
102 returns non-zero if <[x]> is infinite. (It is equivalent to
103 (<<fpclassify>>(<[x]>) == FP_INFINITE).)
106 returns non-zero if <[x]> is NaN. (It is equivalent to
107 (<<fpclassify>>(<[x]>) == FP_NAN).)
109 o <<isnormal>>(<[x]>)
110 returns non-zero if <[x]> is normal. (It is equivalent to
111 (<<fpclassify>>(<[x]>) == FP_NORMAL).)
114 The archaic SUSv2 functions provide information on the floating-point
117 There are five major number formats ("exponent" referring to the
118 biased exponent in the binary-encoded number):
121 A number which contains all zero bits, excluding the sign bit.
123 A number with a zero exponent but a nonzero fraction.
125 A number with an exponent and a fraction.
127 A number with an all 1's exponent and a zero fraction.
129 A number with an all 1's exponent and a nonzero fraction.
133 <<isnan>> returns 1 if the argument is a nan. <<isinf>>
134 returns 1 if the argument is infinity. <<finite>> returns 1 if the
135 argument is zero, subnormal or normal.
137 The <<isnanf>>, <<isinff>> and <<finitef>> functions perform the same
138 operations as their <<isnan>>, <<isinf>> and <<finite>>
139 counterparts, but on single-precision floating-point numbers.
141 It should be noted that the C99 standard dictates that <<isnan>>
142 and <<isinf>> are macros that operate on multiple types of
143 floating-point. The SUSv2 standard declares <<isnan>> as
144 a function taking double. Newlib has decided to declare
145 them both as functions and as macros in math.h to
146 maintain backward compatibility.
149 @comment Formatting note: "$@" forces a new line
150 The fpclassify macro returns the value corresponding to the appropriate FP_ macro.@*
151 The isfinite macro returns nonzero if <[x]> is finite, else 0.@*
152 The isinf macro returns nonzero if <[x]> is infinite, else 0.@*
153 The isnan macro returns nonzero if <[x]> is an NaN, else 0.@*
154 The isnormal macro returns nonzero if <[x]> has a normal value, else 0.
157 math.h macros are C99, POSIX.1-2001.
159 The functions originate from BSD; isnan was listed in the X/Open
160 Portability Guide and Single Unix Specification, but was dropped when
161 the macro was standardized in POSIX.1-2001.
178 * isnan(x) returns 1 is x is nan, else 0;
181 * The C99 standard dictates that isnan is a macro taking
182 * multiple floating-point types while the SUSv2 standard
183 * notes it is a function taking a double argument. Newlib
184 * has chosen to declare it both as a function and as a macro in
185 * <math.h> for compatibility.
191 #ifndef _DOUBLE_IS_32BITS
203 EXTRACT_WORDS(hx
,lx
,x
);
205 hx
|= (__uint32_t
)(lx
|(-lx
))>>31;
206 hx
= 0x7ff00000 - hx
;
207 return (int)(((__uint32_t
)(hx
))>>31);
210 #endif /* _DOUBLE_IS_32BITS */