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