Subversion Repositories Kolibri OS

Rev

Rev 4872 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
 
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
13
 
14
FUNCTION
15
<>, <>, <>, <>, and <>--floating-point classification macros; <>, <>, <>, <>, <>, <>--test for exceptional numbers
16
17
 
18
INDEX
19
	fpclassify
20
INDEX
21
	isfinite
22
INDEX
23
	isinf
24
INDEX
25
	isnan
26
INDEX
27
	isnormal
28
@c C99 end)
29
@c SUSv2 (start
30
INDEX
31
	isnan
32
INDEX
33
	isinf
34
INDEX
35
	finite
36
37
 
38
	isnanf
39
INDEX
40
	isinff
41
INDEX
42
	finitef
43
@c SUSv2 end)
44
45
 
46
	[C99 standard macros:]
47
	#include 
48
	int fpclassify(real-floating <[x]>);
49
	int isfinite(real-floating <[x]>);
50
	int isinf(real-floating <[x]>);
51
	int isnan(real-floating <[x]>);
52
	int isnormal(real-floating <[x]>);
53
54
 
55
	#include 
56
	int isnan(double <[arg]>);
57
	int isinf(double <[arg]>);
58
	int finite(double <[arg]>);
59
	int isnanf(float <[arg]>);
60
	int isinff(float <[arg]>);
61
	int finitef(float <[arg]>);
62
63
 
64
<>, <>, <>, <>, and <> are macros
65
defined for use in classifying floating-point numbers.  This is a help because
66
of special "values" like NaN and infinities.  In the synopses shown,
67
"real-floating" indicates that the argument is an expression of real floating
68
type.  These function-like macros are C99 and POSIX-compliant, and should be
69
used instead of the now-archaic SUSv2 functions.
70
71
 
72
subnormal, zero, or into another implementation-defined category.  First, an
73
argument represented in a format wider than its semantic type is converted to
74
its semantic type.  Then classification is based on the type of the argument.
75
The <> macro returns the value of the number classification macro
76
appropriate to the value of its argument:
77
78
 
79
o FP_INFINITE
80
	<[x]> is either plus or minus infinity;
81
o FP_NAN
82
	<[x]> is "Not A Number" (plus or minus);
83
o FP_NORMAL
84
	<[x]> is a "normal" number (i.e. is none of the other special forms);
85
o FP_SUBNORMAL
86
	<[x]> is too small be stored as a regular normalized number (i.e. loss of precision is likely); or
87
o FP_ZERO
88
	<[x]> is 0 (either plus or minus).
89
o-
90
91
 
92
classifying floating-point numbers, providing the following equivalent
93
relations:
94
95
 
96
o <>(<[x]>)
97
returns non-zero if <[x]> is finite.  (It is equivalent to
98
(<>(<[x]>) != FP_INFINITE  &&  <>(<[x]>) != FP_NAN).)
99
100
 
101
returns non-zero if <[x]> is infinite.  (It is equivalent to
102
(<>(<[x]>) == FP_INFINITE).)
103
104
 
105
returns non-zero if <[x]> is NaN.  (It is equivalent to
106
(<>(<[x]>) == FP_NAN).)
107
108
 
109
returns non-zero if <[x]> is normal.  (It is equivalent to
110
(<>(<[x]>) == FP_NORMAL).)
111
o-
112
113
 
114
	argument supplied.
115
116
 
117
	biased exponent in the binary-encoded number):
118
	o+
119
	o zero
120
	  A number which contains all zero bits, excluding the sign bit.
121
	o subnormal
122
	  A number with a zero exponent but a nonzero fraction.
123
	o normal
124
	  A number with an exponent and a fraction.
125
     	o infinity
126
	  A number with an all 1's exponent and a zero fraction.
127
	o NAN
128
	  A number with an all 1's exponent and a nonzero fraction.
129
130
 
131
132
 
133
	returns 1 if the argument is infinity.  <> returns 1 if the
134
	argument is zero, subnormal or normal.
135
136
 
137
	operations as their <>, <> and <>
138
	counterparts, but on single-precision floating-point numbers.
139
140
 
141
	and <> are macros that operate on multiple types of
142
	floating-point.  The SUSv2 standard declares <> as
143
	a function taking double.  Newlib has decided to declare
144
	them both as macros in math.h and as functions in ieeefp.h to
145
	maintain backward compatibility.
146
147
 
148
@comment Formatting note:  "$@" forces a new line
149
The fpclassify macro returns the value corresponding to the appropriate FP_ macro.@*
150
The isfinite macro returns nonzero if <[x]> is finite, else 0.@*
151
The isinf macro returns nonzero if <[x]> is infinite, else 0.@*
152
The isnan macro returns nonzero if <[x]> is an NaN, else 0.@*
153
The isnormal macro returns nonzero if <[x]> has a normal value, else 0.
154
155
 
156
math.h macros are C99, POSIX.
157
158
 
159
160
 
161
	isnan - pure
162
QUICKREF
163
	isinf - pure
164
QUICKREF
165
	finite - pure
166
QUICKREF
167
	isnan - pure
168
QUICKREF
169
	isinf - pure
170
QUICKREF
171
	finite - pure
172
*/
173
174
 
175
 * isnan(x) returns 1 is x is nan, else 0;
176
 * no branching!
177
 *
178
 * The C99 standard dictates that isnan is a macro taking
179
 * multiple floating-point types while the SUSv2 standard
180
 * notes it is a function taking a double argument.  Newlib
181
 * has chosen to implement it as a macro in  and
182
 * declare it as a function in .
183
 */
184
185
 
186
#include 
187
188
 
189
190
 
191
	int isnan(double x)
192
#else
193
	int isnan(x)
194
	double x;
195
#endif
196
{
197
	__int32_t hx,lx;
198
	EXTRACT_WORDS(hx,lx,x);
199
	hx &= 0x7fffffff;
200
	hx |= (__uint32_t)(lx|(-lx))>>31;
201
	hx = 0x7ff00000 - hx;
202
	return (int)(((__uint32_t)(hx))>>31);
203
}
204
205
 
206