OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libm/] [fpmacros.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/***********************************************************************
2
**  File:  fpmacros.c
3
**
4
**  Contains:  C source code for implementations of floating-point
5
**             functions which involve float format numbers, as
6
**             defined in header <fp.h>.  In particular, this file
7
**             contains implementations of functions
8
**              __fpclassify(d,f), __isnormal(d,f), __isfinite(d,f),
9
**             __isnan(d,f), and __signbit(d,f).  This file targets
10
**             PowerPC platforms.
11
**
12
**  Written by:   Robert A. Murley, Ali Sazegari
13
**
14
**  Copyright:   c 2001 by Apple Computer, Inc., all rights reserved
15
**
16
**  Change History (most recent first):
17
**
18
**     07 Jul 01   ram      First created from fpfloatfunc.c, fp.c,
19
**                              classify.c and sign.c in MathLib v3 Mac OS9.
20
**
21
***********************************************************************/
22
 
23
#include     <features.h>
24
#include     <sys/types.h>
25
#include     <math.h>
26
#include     "fp_private.h"
27
 
28
#define SIGN_MASK 0x80000000
29
#define NSIGN_MASK 0x7fffffff
30
#define FEXP_MASK 0x7f800000
31
#define FFRAC_MASK 0x007fffff
32
 
33
/***********************************************************************
34
   int __fpclassifyf(float x) returns the classification code of the
35
   argument x, as defined in <fp.h>.
36
 
37
   Exceptions:  INVALID signaled if x is a signaling NaN; in this case,
38
                the FP_QNAN code is returned.
39
 
40
   Calls:  none
41
***********************************************************************/
42
 
43
int __fpclassifyf ( float x )
44
{
45
   unsigned int iexp;
46
 
47
   union {
48
      u_int32_t lval;
49
      float fval;
50
   } z;
51
 
52
   z.fval = x;
53
   iexp = z.lval & FEXP_MASK;                 /* isolate float exponent */
54
 
55
   if (iexp == FEXP_MASK) {                   /* NaN or INF case */
56
      if ((z.lval & 0x007fffff) == 0)
57
         return FP_INFINITE;
58
        return FP_NAN;
59
   }
60
 
61
   if (iexp != 0)                             /* normal float */
62
      return FP_NORMAL;
63
 
64
   if (x == 0.0)
65
      return FP_ZERO;             /* zero */
66
   else
67
      return FP_SUBNORMAL;        /* must be subnormal */
68
}
69
 
70
 
71
/***********************************************************************
72
      Function __fpclassify,
73
      Implementation of classify of a double number for the PowerPC.
74
 
75
   Exceptions:  INVALID signaled if x is a signaling NaN; in this case,
76
                the FP_QNAN code is returned.
77
 
78
   Calls:  none
79
***********************************************************************/
80
 
81
int __fpclassify ( double arg )
82
{
83
        register unsigned int exponent;
84
      union
85
            {
86
            dHexParts hex;
87
            double dbl;
88
            } x;
89
 
90
        x.dbl = arg;
91
 
92
        exponent = x.hex.high & dExpMask;
93
        if ( exponent == dExpMask )
94
                {
95
                if ( ( ( x.hex.high & dHighMan ) | x.hex.low ) == 0 )
96
                        return FP_INFINITE;
97
                else
98
                return FP_NAN;
99
                }
100
        else if ( exponent != 0)
101
                return FP_NORMAL;
102
        else {
103
                if ( arg == 0.0 )
104
                        return FP_ZERO;
105
                else
106
                        return FP_SUBNORMAL;
107
                }
108
}
109
 
110
 
111
/***********************************************************************
112
   int __isnormalf(float x) returns nonzero if and only if x is a
113
   normalized float number and zero otherwise.
114
 
115
   Exceptions:  INVALID is raised if x is a signaling NaN; in this case,
116
                zero is returned.
117
 
118
   Calls:  none
119
***********************************************************************/
120
 
121
int __isnormalf ( float x )
122
{
123
   unsigned int iexp;
124
   union {
125
      u_int32_t lval;
126
      float fval;
127
   } z;
128
 
129
   z.fval = x;
130
   iexp = z.lval & FEXP_MASK;                 /* isolate float exponent */
131
   return ((iexp != FEXP_MASK) && (iexp != 0));
132
}
133
 
134
 
135
int __isnormal ( double x )
136
{
137
        return ( __fpclassify ( x ) == FP_NORMAL );
138
}
139
 
140
 
141
/***********************************************************************
142
   int __isfinitef(float x) returns nonzero if and only if x is a
143
   finite (normal, subnormal, or zero) float number and zero otherwise.
144
 
145
   Exceptions:  INVALID is raised if x is a signaling NaN; in this case,
146
                zero is returned.
147
 
148
   Calls:  none
149
***********************************************************************/
150
 
151
int __finitef ( float x )
152
{
153
   union {
154
      u_int32_t lval;
155
      float fval;
156
   } z;
157
 
158
   z.fval = x;
159
   return ((z.lval & FEXP_MASK) != FEXP_MASK);
160
}
161
weak_alias (__finitef, finitef)
162
 
163
int __finite ( double x )
164
{
165
        return ( __fpclassify ( x ) >= FP_ZERO );
166
}
167
weak_alias (__finite, finite)
168
 
169
 
170
/***********************************************************************
171
   int __signbitf(float x) returns nonzero if and only if the sign
172
   bit of x is set and zero otherwise.
173
 
174
   Exceptions:  INVALID is raised if x is a signaling NaN.
175
 
176
   Calls:  none
177
***********************************************************************/
178
 
179
int __signbitf ( float x )
180
{
181
   union {
182
      u_int32_t lval;
183
      float fval;
184
   } z;
185
 
186
   z.fval = x;
187
   return ((z.lval & SIGN_MASK) != 0);
188
}
189
 
190
 
191
/***********************************************************************
192
      Function sign of a double.
193
      Implementation of sign bit for the PowerPC.
194
 
195
   Calls:  none
196
***********************************************************************/
197
 
198
int __signbit ( double arg )
199
{
200
      union
201
            {
202
            dHexParts hex;
203
            double dbl;
204
            } x;
205
      int sign;
206
 
207
      x.dbl = arg;
208
      sign = ( ( x.hex.high & dSgnMask ) == dSgnMask ) ? 1 : 0;
209
      return sign;
210
}
211
 
212
 
213
/***********************************************************************
214
* int __isinff(float x) returns -1 if value represents  negative
215
*       infinity,  1  if value represents positive infinity,
216
*       and 0 otherwise.
217
*
218
* Calls:  __signbit
219
* +***********************************************************************/
220
int __isinff ( float x )
221
{
222
    int class = __fpclassifyf(x);
223
    if ( class == FP_INFINITE ) {
224
        return ( (__signbitf(x)) ? -1 : 1);
225
    }
226
    return 0;
227
}
228
weak_alias (__isinff, isinff)
229
 
230
int __isinf ( double x )
231
{
232
    int class = __fpclassify(x);
233
    if ( class == FP_INFINITE ) {
234
        return ( (__signbit(x)) ? -1 : 1);
235
    }
236
    return 0;
237
}
238
weak_alias (__isinf, isinf)
239
 
240
#if 0
241
int __isinfl ( long double x )
242
{
243
    int class = __fpclassify(x);
244
    if ( class == FP_INFINITE ) {
245
        return ( (__signbit(x)) ? -1 : 1);
246
    }
247
    return 0;
248
}
249
weak_alias (__isinfl, isinfl);
250
#endif
251
 
252
/***********************************************************************
253
   int __isnanf(float x) returns nonzero if and only if x is a
254
   NaN and zero otherwise.
255
 
256
   Exceptions:  INVALID is raised if x is a signaling NaN; in this case,
257
                nonzero is returned.
258
 
259
   Calls:  none
260
***********************************************************************/
261
 
262
int __isnanf ( float x )
263
{
264
   union {
265
      u_int32_t lval;
266
      float fval;
267
   } z;
268
 
269
   z.fval = x;
270
   return (((z.lval&FEXP_MASK) == FEXP_MASK) && ((z.lval&FFRAC_MASK) != 0));
271
}
272
weak_alias (__isnanf, isnanf);
273
 
274
int __isnan ( double x )
275
{
276
        int class = __fpclassify(x);
277
        return ( class == FP_NAN );
278
}
279
weak_alias (__isnan, isnan);
280
 
281
#if 0
282
int __isnanl ( long double x )
283
{
284
        int class = __fpclassify(x);
285
        return ( class == FP_NAN );
286
}
287
weak_alias (__isnanl, isnanl);
288
#endif
289
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.