source: trunk/libs/newlib/src/newlib/libm/math/wf_pow.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.3 KB
Line 
1/* wf_pow.c -- float version of w_pow.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16/*
17 * wrapper powf(x,y) return x**y
18 */
19
20#include "fdlibm.h"
21#if __OBSOLETE_MATH
22#include <errno.h>
23
24#ifdef __STDC__
25        float powf(float x, float y)    /* wrapper powf */
26#else
27        float powf(x,y)                 /* wrapper powf */
28        float x,y;
29#endif
30{
31#ifdef _IEEE_LIBM
32        return  __ieee754_powf(x,y);
33#else
34        float z;
35        struct exception exc;
36        z=__ieee754_powf(x,y);
37        if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
38        if(isnan(x)) {
39            if(y==(float)0.0) { 
40                /* powf(NaN,0.0) */
41                /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
42                exc.type = DOMAIN;
43                exc.name = "powf";
44                exc.err = 0;
45                exc.arg1 = (double)x;
46                exc.arg2 = (double)y;
47                exc.retval = 1.0;
48                if (_LIB_VERSION == _IEEE_ ||
49                    _LIB_VERSION == _POSIX_) exc.retval = 1.0;
50                else if (!matherr(&exc)) {
51                        errno = EDOM;
52                }
53                if (exc.err != 0)
54                   errno = exc.err;
55                return (float)exc.retval; 
56            } else 
57                return z;
58        }
59        if(x==(float)0.0){ 
60            if(y==(float)0.0) {
61                /* powf(0.0,0.0) */
62                /* error only if _LIB_VERSION == _SVID_ */
63                exc.type = DOMAIN;
64                exc.name = "powf";
65                exc.err = 0;
66                exc.arg1 = (double)x;
67                exc.arg2 = (double)y;
68                exc.retval = 0.0;
69                if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
70                else if (!matherr(&exc)) {
71                        errno = EDOM;
72                }
73                if (exc.err != 0)
74                   errno = exc.err;
75                return (float)exc.retval; 
76            }
77            if(finitef(y)&&y<(float)0.0) {
78                /* 0**neg */
79                exc.type = DOMAIN;
80                exc.name = "powf";
81                exc.err = 0;
82                exc.arg1 = (double)x;
83                exc.arg2 = (double)y;
84                if (_LIB_VERSION == _SVID_) 
85                  exc.retval = 0.0;
86                else
87                  exc.retval = -HUGE_VAL;
88                if (_LIB_VERSION == _POSIX_)
89                  errno = EDOM;
90                else if (!matherr(&exc)) {
91                  errno = EDOM;
92                }
93                if (exc.err != 0)
94                   errno = exc.err;
95                return (float)exc.retval; 
96            }
97            return z;
98        }
99        if(!finitef(z)) {
100            if(finitef(x)&&finitef(y)) {
101                if(isnan(z)) {
102                    /* neg**non-integral */
103                    exc.type = DOMAIN;
104                    exc.name = "powf";
105                    exc.err = 0;
106                    exc.arg1 = (double)x;
107                    exc.arg2 = (double)y;
108                    if (_LIB_VERSION == _SVID_) 
109                        exc.retval = 0.0;
110                    else 
111                        /* Use a float divide, to avoid a soft-float double
112                           divide call on single-float only targets.  */
113                        exc.retval = (0.0f/0.0f);       /* X/Open allow NaN */
114                    if (_LIB_VERSION == _POSIX_) 
115                        errno = EDOM;
116                    else if (!matherr(&exc)) {
117                        errno = EDOM;
118                    }
119                    if (exc.err != 0)
120                        errno = exc.err;
121                    return (float)exc.retval; 
122                } else {
123                    /* powf(x,y) overflow */
124                    exc.type = OVERFLOW;
125                    exc.name = "powf";
126                    exc.err = 0;
127                    exc.arg1 = (double)x;
128                    exc.arg2 = (double)y;
129                    if (_LIB_VERSION == _SVID_) {
130                       exc.retval = HUGE;
131                       y *= 0.5;
132                       if(x<0.0f&&rintf(y)!=y) exc.retval = -HUGE;
133                    } else {
134                       exc.retval = HUGE_VAL;
135                       y *= 0.5;
136                       if(x<0.0f&&rintf(y)!=y) exc.retval = -HUGE_VAL;
137                    }
138                    if (_LIB_VERSION == _POSIX_)
139                        errno = ERANGE;
140                    else if (!matherr(&exc)) {
141                        errno = ERANGE;
142                    }
143                    if (exc.err != 0)
144                        errno = exc.err;
145                    return (float)exc.retval; 
146                }
147            }
148        } 
149        if(z==(float)0.0&&finitef(x)&&finitef(y)) {
150            /* powf(x,y) underflow */
151            exc.type = UNDERFLOW;
152            exc.name = "powf";
153            exc.err = 0;
154            exc.arg1 = (double)x;
155            exc.arg2 = (double)y;
156            exc.retval =  0.0;
157            if (_LIB_VERSION == _POSIX_)
158                errno = ERANGE;
159            else if (!matherr(&exc)) {
160                errno = ERANGE;
161            }
162            if (exc.err != 0)
163                errno = exc.err;
164            return (float)exc.retval; 
165        }
166        return z;
167#endif
168}
169
170#ifdef _DOUBLE_IS_32BITS
171
172#ifdef __STDC__
173        double pow(double x, double y)
174#else
175        double pow(x,y)
176        double x,y;
177#endif
178{
179        return (double) powf((float) x, (float) y);
180}
181
182#endif /* defined(_DOUBLE_IS_32BITS) */
183#endif /* __OBSOLETE_MATH */
Note: See TracBrowser for help on using the repository browser.