xref: /netbsd-src/lib/libm/src/s_isnan.c (revision ae1bfcddc410612bc8c58b807e1830becb69a24c)
1 /* @(#)s_isnan.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 
13 #ifndef lint
14 static char rcsid[] = "$Id: s_isnan.c,v 1.4 1994/03/03 17:04:39 jtc Exp $";
15 #endif
16 
17 /*
18  * isnan(x) returns 1 is x is nan, else 0;
19  * no branching!
20  */
21 
22 #include <math.h>
23 #include <machine/endian.h>
24 
25 #if BYTE_ORDER == LITTLE_ENDIAN
26 #define n0	1
27 #else
28 #define n0	0
29 #endif
30 
31 #ifdef __STDC__
32 static const double one = 1.0;
33 #else
34 static double one = 1.0;
35 #endif
36 
37 #ifdef __STDC__
38 	int isnan(double x)
39 #else
40 	int isnan(x)
41 	double x;
42 #endif
43 {
44 	int hx,lx;
45 	hx = (*(n0+(int*)&x)&0x7fffffff);
46 	lx = *(1-n0+(int*)&x);
47 	hx |= (unsigned)(lx|(-lx))>>31;
48 	hx = 0x7ff00000 - hx;
49 	return ((unsigned)(hx))>>31;
50 }
51