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