Metatarget for copying of testfile fixed.
[AROS.git] / workbench / libs / mathieeesingtrans / ieeespexp.c
blobc91930e686d4c4c4518bab6281b69cf2b9e3261e
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingtrans_intern.h"
8 /*
9 FUNCTION
10 Calculate e^x
12 RESULT
13 IEEE single precision number
15 flags:
16 zero : result is zero
17 negative : 0
18 overflow : the result was out of range for the IEEE single precision
19 format
21 NOTES
23 EXAMPLE
25 BUGS
27 SEE ALSO
29 INTERNALS
30 <code>
31 e^(>= 89): return 0x7f800000;
32 e^(2^(<=-24)): return one;
33 </code>
35 HISTORY
38 AROS_LH1(float, IEEESPExp,
39 AROS_LHA(float, y, D0),
40 struct Library *, MathIeeeSingTransBase, 13, MathIeeeSingTrans
43 AROS_LIBFUNC_INIT
45 const LONG ExpTable[] =
47 0x6da12cc2, /* e^64 */
48 0x568fa1fe, /* e^32 */
49 0x4b07975e, /* e^16 */
50 0x453a4f53, /* e^8 */
51 0x425a6481, /* e^4 */
52 0x40ec7325, /* e^2 */
53 0x402df854, /* e^1 */
54 0x3fd3094c, /* e^(1/2) */
55 0x3fa45af2, /* e^(1/4) */
56 0x3f910b02, /* e^(1/8) */
57 0x3f88415b, /* e^(1/16) */
58 0x3f84102b, /* e^(1/32) */
59 0x3f820405, /* e^(1/64) */
60 0x3f810101, /* e^(1/128) */
61 0x3f808040, /* e^(1/256) */
62 0x3f804010, /* e^(1/512) */
63 0x3f802004, /* e^(1/1024) */
64 0x3f801001, /* e^(1/2048) */
65 0x3f800800, /* e^(1/4096) */
66 0x3f800400, /* e^(1/8192) */
67 0x3f800200, /* e^(1/16384) */
68 0x3f800100, /* e^(1/32768) */
69 0x3f800080, /* e^(1/65536) */
70 0x3f800040, /* e^(1/131072) */
71 0x3f800020, /* e^(1/262144) */
72 0x3f800010, /* e^(1/524288) */
73 0x3f800008, /* e^(1/1048576) */
74 0x3f800004, /* e^(1/2097152) */
75 0x3f800002, /* e^(1/4194304) */
76 0x3f800001, /* e^(1/8388608) */
78 ULONG Res, i;
79 LONG Mantisse;
80 char Exponent;
82 Exponent = ((y & IEEESPExponent_Mask) >> 23) -0x7f;
84 /* e^0 = 1, e^(2^(<=-24)) = 1 */
85 if ( 0 == y || Exponent <= -24 ) return one;
87 /* e^(>= 89) = overflow) */
88 if (Exponent > 6)
90 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
91 return IEEESP_Pinfty;
94 i = 6 - Exponent;
96 Mantisse = (y & IEEESPMantisse_Mask) << 9;
97 Res = ExpTable[i++];
99 while ( 0 != Mantisse && i <= 29 )
101 /* is the highest bit set? */
102 if ( Mantisse < 0 )
104 Res = IEEESPMul(Res, ExpTable[i]);
105 if (0 == Res)
107 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
108 return Res;
110 if (IEEESP_Pinfty == Res)
112 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
113 return Res;
116 i++;
117 Mantisse <<= 1;
120 if ( y < 0) return IEEESPDiv(one, Res);
122 return Res;
124 AROS_LIBFUNC_EXIT