source: trunk/libs/newlib/src/newlib/libm/math/wf_exp.c @ 452

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

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

File size: 2.2 KB
Line 
1/* wf_exp.c -- float version of w_exp.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 expf(x)
18 */
19
20#include "fdlibm.h"
21#if __OBSOLETE_MATH
22#include <errno.h>
23
24#ifdef __STDC__
25static const float
26#else
27static float
28#endif
29o_threshold=  8.8721679688e+01,  /* 0x42b17180 */
30u_threshold= -1.0397208405e+02;  /* 0xc2cff1b5 */
31
32#ifdef __STDC__
33        float expf(float x)             /* wrapper expf */
34#else
35        float expf(x)                   /* wrapper expf */
36        float x;
37#endif
38{
39#ifdef _IEEE_LIBM
40        return __ieee754_expf(x);
41#else
42        float z;
43        struct exception exc;
44        z = __ieee754_expf(x);
45        if(_LIB_VERSION == _IEEE_) return z;
46        if(finitef(x)) {
47            if(x>o_threshold) {
48                /* expf(finite) overflow */
49#ifndef HUGE_VAL
50#define HUGE_VAL inf
51                double inf = 0.0;
52
53                SET_HIGH_WORD(inf,0x7ff00000);  /* set inf to infinite */
54#endif
55                exc.type = OVERFLOW;
56                exc.name = "expf";
57                exc.err = 0;
58                exc.arg1 = exc.arg2 = (double)x;
59                if (_LIB_VERSION == _SVID_)
60                  exc.retval = HUGE;
61                else
62                  exc.retval = HUGE_VAL;
63                if (_LIB_VERSION == _POSIX_)
64                  errno = ERANGE;
65                else if (!matherr(&exc)) {
66                        errno = ERANGE;
67                }
68                if (exc.err != 0)
69                   errno = exc.err;
70                return exc.retval; 
71            } else if(x<u_threshold) {
72                /* expf(finite) underflow */
73                exc.type = UNDERFLOW;
74                exc.name = "expf";
75                exc.err = 0;
76                exc.arg1 = exc.arg2 = (double)x;
77                exc.retval = 0.0;
78                if (_LIB_VERSION == _POSIX_)
79                  errno = ERANGE;
80                else if (!matherr(&exc)) {
81                        errno = ERANGE;
82                }
83                if (exc.err != 0)
84                   errno = exc.err;
85                return exc.retval; 
86            } 
87        } 
88        return z;
89#endif
90}
91
92#ifdef _DOUBLE_IS_32BITS
93
94#ifdef __STDC__
95        double exp(double x)
96#else
97        double exp(x)
98        double x;
99#endif
100{
101        return (double) expf((float) x);
102}
103
104#endif /* defined(_DOUBLE_IS_32BITS) */
105#endif /* __OBSOLETE_MATH */
Note: See TracBrowser for help on using the repository browser.