]> git.saurik.com Git - apple/libc.git/blob - gen.subproj/isnan.c
Libc-186.tar.gz
[apple/libc.git] / gen.subproj / isnan.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* @(#)s_isnan.c 5.1 93/09/24 */
23 /*
24 * ====================================================
25 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
26 *
27 * Developed at SunPro, a Sun Microsystems, Inc. business.
28 * Permission to use, copy, modify, and distribute this
29 * software is freely granted, provided that this notice
30 * is preserved.
31 * ====================================================
32 */
33
34 #if defined(LIBM_SCCS) && !defined(lint)
35 static char rcsid[] = "$NetBSD: s_isnan.c,v 1.8 1995/05/10 20:47:36 jtc Exp $";
36 #endif
37
38 /*
39 * isnan(x) returns 1 is x is nan, else 0;
40 * no branching!
41 */
42
43 #include <sys/types.h>
44
45 typedef union
46 {
47 double value;
48 struct
49 {
50 #if defined(__BIG_ENDIAN__)
51 u_int32_t msw;
52 u_int32_t lsw;
53 #else
54 u_int32_t lsw;
55 u_int32_t msw;
56 #endif
57 } parts;
58 } ieee_double_shape_type;
59 /* Get two 32 bit ints from a double. */
60
61 #define EXTRACT_WORDS(ix0,ix1,d) \
62 do { \
63 ieee_double_shape_type ew_u; \
64 ew_u.value = (d); \
65 (ix0) = ew_u.parts.msw; \
66 (ix1) = ew_u.parts.lsw; \
67 } while (0)
68
69
70 #ifdef __STDC__
71 int isnan(double x)
72 #else
73 int isnan(x)
74 double x;
75 #endif
76 {
77 int32_t hx,lx;
78 EXTRACT_WORDS(hx,lx,x);
79 hx &= 0x7fffffff;
80 hx |= (u_int32_t)(lx|(-lx))>>31;
81 hx = 0x7ff00000 - hx;
82 return (int)((u_int32_t)(hx))>>31;
83 }