5
* Floating point numeric utilities
11
* double ceil(), floor(), frexp(), ldexp(); --- gone
12
* int signbit(), isnan(), isfinite();
18
* y = frexp( x, &expnt ); -gone
19
* y = ldexp( x, n ); -gone
28
* All four routines return a double precision floating point
31
* floor() returns the largest integer less than or equal to x.
32
* It truncates toward minus infinity.
34
* ceil() returns the smallest integer greater than or equal
35
* to x. It truncates toward plus infinity.
37
* frexp() extracts the exponent from x. It returns an integer
38
* power of two to expnt and the significand between 0.5 and 1
39
* to y. Thus x = y * 2**expn.
41
* ldexp() multiplies x by 2**n.
43
* signbit(x) returns 1 if the sign bit of x is 1, else 0.
45
* These functions are part of the standard C run time library
46
* for many but not all C compilers. The ones supplied are
47
* written in C for either DEC or IEEE arithmetic. They should
48
* be used only if your compiler library does not already have
51
* The IEEE versions assume that denormal numbers are implemented
52
* in the arithmetic. Some modifications will be required if
53
* the arithmetic has abrupt rather than gradual underflow.
58
Cephes Math Library Release 2.3: March, 1995
59
Copyright 1984, 1995 by Stephen L. Moshier
75
extern int signbit ( double x );
76
extern int cephes_isnan ( double x );
77
extern int isfinite ( double x );
80
/* Return 1 if the sign bit of x is 1, else 0. */
94
if( sizeof(int) == 4 )
100
return( u.s[3] < 0 );
103
return( u.i[0] < 0 );
109
return( u.s[3] < 0 );
112
return( u.s[3] < 0 );
115
return( u.s[0] < 0 );
121
/* Return 1 if x is a number that is Not a Number, else return 0. */
123
int cephes_isnan(double x)
135
if( sizeof(int) == 4 )
138
if( ((u.i[1] & 0x7ff00000) == 0x7ff00000)
139
&& (((u.i[1] & 0x000fffff) != 0) || (u.i[0] != 0)))
143
if( (u.s[1] & 0x7fff) == 0)
145
if( (u.s[2] | u.s[1] | u.s[0]) != 0 )
150
if( ((u.i[0] & 0x7ff00000) == 0x7ff00000)
151
&& (((u.i[0] & 0x000fffff) != 0) || (u.i[1] != 0)))
157
{ /* size int not 4 */
159
if( (u.s[3] & 0x7ff0) == 0x7ff0)
161
if( ((u.s[3] & 0x000f) | u.s[2] | u.s[1] | u.s[0]) != 0 )
166
if( (u.s[3] & 0x7fff) == 0)
168
if( (u.s[2] | u.s[1] | u.s[0]) != 0 )
173
if( (u.s[0] & 0x7ff0) == 0x7ff0)
175
if( ((u.s[0] & 0x000f) | u.s[1] | u.s[2] | u.s[3]) != 0 )
180
} /* size int not 4 */
189
/* Return 1 if x is not infinite and is not a NaN. */
204
if( sizeof(int) == 4 )
207
if( (u.i[1] & 0x7ff00000) != 0x7ff00000)
211
if( (u.s[3] & 0x7fff) != 0)
215
if( (u.i[0] & 0x7ff00000) != 0x7ff00000)
223
if( (u.s[3] & 0x7ff0) != 0x7ff0)
227
if( (u.s[3] & 0x7fff) != 0)
231
if( (u.s[0] & 0x7ff0) != 0x7ff0)