~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/special/cephes/isnan.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*                                                      isnan()
 
2
 *                                                      signbit()
 
3
 *                                                      isfinite()
 
4
 *
 
5
 *      Floating point numeric utilities
 
6
 *
 
7
 *
 
8
 *
 
9
 * SYNOPSIS:
 
10
 *
 
11
 * double ceil(), floor(), frexp(), ldexp(); --- gone
 
12
 * int signbit(), isnan(), isfinite();
 
13
 * double x, y;
 
14
 * int expnt, n;
 
15
 *
 
16
 * y = floor(x);             -gone 
 
17
 * y = ceil(x);              -gone
 
18
 * y = frexp( x, &expnt );   -gone
 
19
 * y = ldexp( x, n );        -gone
 
20
 * n = signbit(x);
 
21
 * n = isnan(x);
 
22
 * n = isfinite(x);
 
23
 *
 
24
 *
 
25
 *
 
26
 * DESCRIPTION:
 
27
 *
 
28
 * All four routines return a double precision floating point
 
29
 * result.
 
30
 *
 
31
 * floor() returns the largest integer less than or equal to x.
 
32
 * It truncates toward minus infinity.
 
33
 *
 
34
 * ceil() returns the smallest integer greater than or equal
 
35
 * to x.  It truncates toward plus infinity.
 
36
 *
 
37
 * frexp() extracts the exponent from x.  It returns an integer
 
38
 * power of two to expnt and the significand between 0.5 and 1
 
39
 * to y.  Thus  x = y * 2**expn.
 
40
 *
 
41
 * ldexp() multiplies x by 2**n.
 
42
 *
 
43
 * signbit(x) returns 1 if the sign bit of x is 1, else 0.
 
44
 *
 
45
 * These functions are part of the standard C run time library
 
46
 * for many but not all C compilers.  The ones supplied are
 
47
 * written in C for either DEC or IEEE arithmetic.  They should
 
48
 * be used only if your compiler library does not already have
 
49
 * them.
 
50
 *
 
51
 * The IEEE versions assume that denormal numbers are implemented
 
52
 * in the arithmetic.  Some modifications will be required if
 
53
 * the arithmetic has abrupt rather than gradual underflow.
 
54
 */
 
55
 
 
56
 
 
57
/*
 
58
Cephes Math Library Release 2.3:  March, 1995
 
59
Copyright 1984, 1995 by Stephen L. Moshier
 
60
*/
 
61
 
 
62
 
 
63
#include "mconf.h"
 
64
 
 
65
#ifdef UNK
 
66
#undef UNK
 
67
#if BIGENDIAN
 
68
#define MIEEE 1
 
69
#else
 
70
#define IBMPC 1
 
71
#endif
 
72
#endif
 
73
 
 
74
#ifdef ANSIPROT
 
75
extern int signbit ( double x );
 
76
extern int cephes_isnan ( double x );
 
77
extern int isfinite ( double x );
 
78
#endif
 
79
 
 
80
/* Return 1 if the sign bit of x is 1, else 0.  */
 
81
 
 
82
int signbit(x)
 
83
double x;
 
84
{
 
85
union
 
86
        {
 
87
        double d;
 
88
        short s[4];
 
89
        int i[2];
 
90
        } u;
 
91
 
 
92
u.d = x;
 
93
 
 
94
if( sizeof(int) == 4 )
 
95
        {
 
96
#ifdef IBMPC
 
97
        return( u.i[1] < 0 );
 
98
#endif
 
99
#ifdef DEC
 
100
        return( u.s[3] < 0 );
 
101
#endif
 
102
#ifdef MIEEE
 
103
        return( u.i[0] < 0 );
 
104
#endif
 
105
        }
 
106
else
 
107
        {
 
108
#ifdef IBMPC
 
109
        return( u.s[3] < 0 );
 
110
#endif
 
111
#ifdef DEC
 
112
        return( u.s[3] < 0 );
 
113
#endif
 
114
#ifdef MIEEE
 
115
        return( u.s[0] < 0 );
 
116
#endif
 
117
        }
 
118
}
 
119
 
 
120
 
 
121
/* Return 1 if x is a number that is Not a Number, else return 0.  */
 
122
 
 
123
int cephes_isnan(double x)
 
124
{
 
125
#ifdef NANS
 
126
union
 
127
        {
 
128
        double d;
 
129
        unsigned short s[4];
 
130
        unsigned int i[2];
 
131
        } u;
 
132
 
 
133
u.d = x;
 
134
 
 
135
if( sizeof(int) == 4 )
 
136
        {
 
137
#ifdef IBMPC
 
138
        if( ((u.i[1] & 0x7ff00000) == 0x7ff00000)
 
139
            && (((u.i[1] & 0x000fffff) != 0) || (u.i[0] != 0)))
 
140
                return 1;
 
141
#endif
 
142
#ifdef DEC
 
143
        if( (u.s[1] & 0x7fff) == 0)
 
144
                {
 
145
                if( (u.s[2] | u.s[1] | u.s[0]) != 0 )
 
146
                        return(1);
 
147
                }
 
148
#endif
 
149
#ifdef MIEEE
 
150
        if( ((u.i[0] & 0x7ff00000) == 0x7ff00000)
 
151
            && (((u.i[0] & 0x000fffff) != 0) || (u.i[1] != 0)))
 
152
                return 1;
 
153
#endif
 
154
        return(0);
 
155
        }
 
156
else
 
157
        { /* size int not 4 */
 
158
#ifdef IBMPC
 
159
        if( (u.s[3] & 0x7ff0) == 0x7ff0)
 
160
                {
 
161
                if( ((u.s[3] & 0x000f) | u.s[2] | u.s[1] | u.s[0]) != 0 )
 
162
                        return(1);
 
163
                }
 
164
#endif
 
165
#ifdef DEC
 
166
        if( (u.s[3] & 0x7fff) == 0)
 
167
                {
 
168
                if( (u.s[2] | u.s[1] | u.s[0]) != 0 )
 
169
                        return(1);
 
170
                }
 
171
#endif
 
172
#ifdef MIEEE
 
173
        if( (u.s[0] & 0x7ff0) == 0x7ff0)
 
174
                {
 
175
                if( ((u.s[0] & 0x000f) | u.s[1] | u.s[2] | u.s[3]) != 0 )
 
176
                        return(1);
 
177
                }
 
178
#endif
 
179
        return(0);
 
180
        } /* size int not 4 */
 
181
 
 
182
#else
 
183
/* No NANS.  */
 
184
return(0);
 
185
#endif
 
186
}
 
187
 
 
188
 
 
189
/* Return 1 if x is not infinite and is not a NaN.  */
 
190
 
 
191
int isfinite(x)
 
192
double x;
 
193
{
 
194
#ifdef INFINITIES
 
195
union
 
196
        {
 
197
        double d;
 
198
        unsigned short s[4];
 
199
        unsigned int i[2];
 
200
        } u;
 
201
 
 
202
u.d = x;
 
203
 
 
204
if( sizeof(int) == 4 )
 
205
        {
 
206
#ifdef IBMPC
 
207
        if( (u.i[1] & 0x7ff00000) != 0x7ff00000)
 
208
                return 1;
 
209
#endif
 
210
#ifdef DEC
 
211
        if( (u.s[3] & 0x7fff) != 0)
 
212
                return 1;
 
213
#endif
 
214
#ifdef MIEEE
 
215
        if( (u.i[0] & 0x7ff00000) != 0x7ff00000)
 
216
                return 1;
 
217
#endif
 
218
        return(0);
 
219
        }
 
220
else
 
221
        {
 
222
#ifdef IBMPC
 
223
        if( (u.s[3] & 0x7ff0) != 0x7ff0)
 
224
                return 1;
 
225
#endif
 
226
#ifdef DEC
 
227
        if( (u.s[3] & 0x7fff) != 0)
 
228
                return 1;
 
229
#endif
 
230
#ifdef MIEEE
 
231
        if( (u.s[0] & 0x7ff0) != 0x7ff0)
 
232
                return 1;
 
233
#endif
 
234
        return(0);
 
235
        }
 
236
#else
 
237
/* No INFINITY.  */
 
238
return(1);
 
239
#endif
 
240
}