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