typo
[AROS.git] / workbench / libs / mathieeesingtrans / ieeespatan.c
blob77a8c4c27de055a5a22410b6fd0df7fbe2eb6d96
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingtrans_intern.h"
8 /*
9 FUNCTION
10 Calculates the angle of a given number representing the tangent
11 of that angle. The angle will be in radians.
14 RESULT
15 IEEE single precision floating point number
17 NOTES
19 EXAMPLE
21 BUGS
23 SEE ALSO
25 INTERNALS
27 HISTORY
30 AROS_LH1(float, IEEESPAtan,
31 AROS_LHA(float, y, D0),
32 struct Library *, MathIeeeSingTransBase, 5, MathIeeeSingTrans
35 AROS_LIBFUNC_INIT
37 LONG yabs = y & (IEEESPMantisse_Mask | IEEESPExponent_Mask);
38 LONG ysquared, ycubed;
40 /* check for +- infinity -> output: +-pi/2 */
41 if (IEEESP_Pinfty == yabs) return (pio2 | (y & IEEESPSign_Mask));
43 /* atan(0) = 0 */
44 if (0 == yabs)
46 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
47 return 0;
50 /* atan(x >= 128) = pi/2 - 1/x */
51 if ( (yabs & IEEESPExponent_Mask) >= 0x43000000)
53 if (yabs == y) /* arg has ppositive sign */
55 SetSR(0, Zero_Bit | Negative_Bit | Overflow_Bit);
56 return IEEESPSub(pio2,IEEESPDiv(one,yabs));
58 else
60 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
61 return (IEEESPSub(pio2,IEEESPDiv(one,yabs))) | IEEESPSign_Mask;
65 /* atan(x >= 64) = pi/2 - 1/x +1/(3*x^3) */
67 ysquared = IEEESPMul(yabs, yabs);
69 if( (yabs & IEEESPExponent_Mask) >= 0x42000000)
71 ycubed = IEEESPMul(yabs, ysquared);
73 /* pi/2 - 1/x + 1/(3*x^3) = pi/2 + (1-3*x^2)/(3*x^3)*/
74 if (yabs == y) /* arg has positive sign */
76 SetSR(0, Zero_Bit | Negative_Bit | Overflow_Bit);
77 return IEEESPAdd
79 pio2, IEEESPDiv
81 IEEESPAdd
83 IEEESPMul(three, ysquared) | IEEESPSign_Mask, one
85 IEEESPMul(three, ycubed)
89 else
91 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
92 return IEEESPAdd
94 pio2, IEEESPDiv
96 IEEESPAdd
98 IEEESPMul(three, ysquared) | IEEESPSign_Mask, one
100 IEEESPMul(three, ycubed)
102 ) | IEEESPSign_Mask;
106 /* atan(x <= 64) */
107 return IEEESPAsin(IEEESPDiv(y,IEEESPSqrt(IEEESPAdd(one,ysquared))));
109 AROS_LIBFUNC_EXIT
110 } /* IEEESPAtan */