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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [math/] [wf_pow.c] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/* 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
#include <errno.h>
22
 
23
#ifdef __STDC__
24
        float powf(float x, float y)    /* wrapper powf */
25
#else
26
        float powf(x,y)                 /* wrapper powf */
27
        float x,y;
28
#endif
29
{
30
#ifdef _IEEE_LIBM
31
        return  __ieee754_powf(x,y);
32
#else
33
        float z;
34
        struct exception exc;
35
        z=__ieee754_powf(x,y);
36
        if(_LIB_VERSION == _IEEE_|| isnanf(y)) return z;
37
        if(isnanf(x)) {
38
            if(y==(float)0.0) {
39
                /* powf(NaN,0.0) */
40
                /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
41
                exc.type = DOMAIN;
42
                exc.name = "powf";
43
                exc.retval = x;
44
                if (_LIB_VERSION == _IEEE_ ||
45
                    _LIB_VERSION == _POSIX_) exc.retval = 1.0;
46
                else if (!matherr(&exc)) {
47
                        errno = EDOM;
48
                }
49
                if (exc.err != 0)
50
                   errno = exc.err;
51
                return (float)exc.retval;
52
            } else
53
                return z;
54
        }
55
        if(x==(float)0.0){
56
            if(y==(float)0.0) {
57
                /* powf(0.0,0.0) */
58
                /* error only if _LIB_VERSION == _SVID_ */
59
                exc.type = DOMAIN;
60
                exc.name = "powf";
61
                exc.retval = 0.0;
62
                if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
63
                else if (!matherr(&exc)) {
64
                        errno = EDOM;
65
                }
66
                if (exc.err != 0)
67
                   errno = exc.err;
68
                return (float)exc.retval;
69
            }
70
            if(finitef(y)&&y<(float)0.0) {
71
                /* 0**neg */
72
                exc.type = DOMAIN;
73
                exc.name = "powf";
74
                if (_LIB_VERSION == _SVID_)
75
                  exc.retval = 0.0;
76
                else
77
                  exc.retval = -HUGE_VAL;
78
                if (_LIB_VERSION == _POSIX_)
79
                  errno = EDOM;
80
                else if (!matherr(&exc)) {
81
                  errno = EDOM;
82
                }
83
                if (exc.err != 0)
84
                   errno = exc.err;
85
                return (float)exc.retval;
86
            }
87
            return z;
88
        }
89
        if(!finitef(z)) {
90
            if(finitef(x)&&finitef(y)) {
91
                if(isnanf(z)) {
92
                    /* neg**non-integral */
93
                    exc.type = DOMAIN;
94
                    exc.name = "powf";
95
                    if (_LIB_VERSION == _SVID_)
96
                        exc.retval = 0.0;
97
                    else
98
                        exc.retval = 0.0/0.0;   /* X/Open allow NaN */
99
                    if (_LIB_VERSION == _POSIX_)
100
                        errno = EDOM;
101
                    else if (!matherr(&exc)) {
102
                        errno = EDOM;
103
                    }
104
                    if (exc.err != 0)
105
                        errno = exc.err;
106
                    return (float)exc.retval;
107
                } else {
108
                    /* powf(x,y) overflow */
109
                    exc.type = OVERFLOW;
110
                    exc.name = "powf";
111
                    if (_LIB_VERSION == _SVID_) {
112
                       exc.retval = HUGE;
113
                       y *= 0.5;
114
                       if(x<0.0&&rint(y)!=y) exc.retval = -HUGE;
115
                    } else {
116
                       exc.retval = HUGE_VAL;
117
                       y *= 0.5;
118
                       if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL;
119
                    }
120
                    if (_LIB_VERSION == _POSIX_)
121
                        errno = ERANGE;
122
                    else if (!matherr(&exc)) {
123
                        errno = ERANGE;
124
                    }
125
                    if (exc.err != 0)
126
                        errno = exc.err;
127
                    return (float)exc.retval;
128
                }
129
            }
130
        }
131
        if(z==(float)0.0&&finitef(x)&&finitef(y)) {
132
            /* powf(x,y) underflow */
133
            exc.type = UNDERFLOW;
134
            exc.name = "powf";
135
            exc.retval =  0.0;
136
            if (_LIB_VERSION == _POSIX_)
137
                errno = ERANGE;
138
            else if (!matherr(&exc)) {
139
                errno = ERANGE;
140
            }
141
            if (exc.err != 0)
142
                errno = exc.err;
143
            return (float)exc.retval;
144
        }
145
        return z;
146
#endif
147
}
148
 
149
#ifdef _DOUBLE_IS_32BITS
150
 
151
#ifdef __STDC__
152
        double pow(double x, double y)
153
#else
154
        double pow(x,y)
155
        double x,y;
156
#endif
157
{
158
        return (double) powf((float) x, (float) y);
159
}
160
 
161
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

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