Line | |
---|
1 | |
---|
2 | /* @(#)s_isnan.c 5.1 93/09/24 */ |
---|
3 | /* |
---|
4 | * ==================================================== |
---|
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
6 | * |
---|
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 |
---|
10 | * is preserved. |
---|
11 | * ==================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | * isnan(x) returns 1 is x is nan, else 0; |
---|
16 | * no branching! |
---|
17 | */ |
---|
18 | |
---|
19 | #include <libm/fdlibm.h> |
---|
20 | |
---|
21 | #ifdef __STDC__ |
---|
22 | static const double one = 1.0; |
---|
23 | #else |
---|
24 | static double one = 1.0; |
---|
25 | #endif |
---|
26 | |
---|
27 | #ifdef __STDC__ |
---|
28 | int isnan(double x) |
---|
29 | #else |
---|
30 | int isnan(x) |
---|
31 | double x; |
---|
32 | #endif |
---|
33 | { |
---|
34 | int n0,hx,lx; |
---|
35 | n0 = ((*(int*)&one)>>29)^1; |
---|
36 | hx = (*(n0+(int*)&x)&0x7fffffff); |
---|
37 | lx = *(1-n0+(int*)&x); |
---|
38 | hx |= (unsigned)(lx|(-lx))>>31; |
---|
39 | hx = 0x7ff00000 - hx; |
---|
40 | return ((unsigned)(hx))>>31; |
---|
41 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.