childs -> children.
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesppow.c
blob573d4b1a51059d14f85b409b883afcbc5ae77a51
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 y raised to the x power (y^x)
12 RESULT
13 IEEE single precision floating point number
16 flags:
17 zero : result is zero
18 negative : result is negative
19 overflow : result is too big
21 NOTES
23 EXAMPLE
25 BUGS
27 SEE ALSO
29 INTERNALS
31 HISTORY
34 AROS_LH2(float, IEEESPPow,
35 AROS_LHA(float, x, D1),
36 AROS_LHA(float, y, D0),
37 struct Library *, MathIeeeSingTransBase, 15, MathIeeeSingTrans
40 AROS_LIBFUNC_INIT
42 /*
43 a ^ b = e^(b * ln a )
44 y ^ x = e^(x * ln y )
46 LONG Res;
48 /* y^x is illegal if y<0 and x is not an integer-value */
49 if (y < 0 && x != IEEESPCeil(x) ) return 0;
51 Res = IEEESPLog( y & (IEEESPMantisse_Mask + IEEESPExponent_Mask) );
52 Res = IEEESPMul(Res, x);
53 Res = IEEESPExp(Res);
55 /*
56 if y < 0 and x was and even integer, the result is positive, otherwise
57 it is negative.
59 if (y < 0 && TRUE == intern_IEEESPisodd(x) ) Res |= IEEESPSign_Mask;
61 if (0 == Res)
63 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
64 return 0;
67 SetSR(0, Zero_Bit | Negative_Bit | Overflow_Bit);
69 if ( Res < 0)
71 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
74 if ( IEEESP_Pinfty == (Res & (IEEESPMantisse_Mask + IEEESPExponent_Mask)) )
76 /* don`t touch the Negative_Bit now!*/
77 SetSR(Overflow_Bit, Zero_Bit | Overflow_Bit);
80 return Res;
82 AROS_LIBFUNC_EXIT