Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesppow.c
blob8760359114b64210cd1b934263a3cec246443a89
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingtrans_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH2(float, IEEESPPow,
14 /* SYNOPSIS */
15 AROS_LHA(float, x, D1),
16 AROS_LHA(float, y, D0),
18 /* LOCATION */
19 struct Library *, MathIeeeSingTransBase, 15, MathIeeeSingTrans)
21 /* FUNCTION
22 Calculate y raised to the x power (y^x)
24 INPUTS
26 RESULT
27 IEEE single precision floating point number
29 flags:
30 zero : result is zero
31 negative : result is negative
32 overflow : result is too big
34 BUGS
36 INTERNALS
38 *****************************************************************************/
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