Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / mathtrans / spsin.c
blob504d266c6d1a97005b8cb4700836019c118e95b2
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathtrans_intern.h"
8 /*
9 FUNCTION
10 Calculate the sine of a given FFP number in radians
12 RESULT
13 Motorola fast floating point number
15 flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : 0
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
28 INTERNALS
29 Algorithm for Calculation of sin(y):
30 <code>
31 z = floor ( |y| / pi );
32 y_1 = |y| - z * pi; => 0 <= y_1 < pi
34 if (y_1 > pi/2 ) then y_1 = pi - y_1;
36 => 0 <= y_1 < pi/2
38 Res = y - y^3/3! + y^5/5! - y^7/7! + y^9/9! - y^11/11! =
39 = y(1+y^2(-1/3!+y^2(1/5!+y^2(-1/7!+y^2(1/9!-1/11!y^2)))));
41 if (y < 0)
42 Res = -Res;
44 if (z was an odd number)
45 Res = -Res;
46 </code>
49 HISTORY
52 AROS_LH1(float, SPSin,
53 AROS_LHA(float, fnum1, D0),
54 struct Library *, MathTransBase, 6, MathTrans
57 AROS_LIBFUNC_INIT
59 LONG z,Res,ysquared,yabs,tmp;
60 yabs = fnum1 & (FFPMantisse_Mask + FFPExponent_Mask);
62 if ((LONG)FFP_Pinfty == yabs)
64 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
65 return FFP_NAN;
68 z = SPFloor(SPDiv(pi, yabs));
69 tmp = SPMul(z,pi);
70 tmp |= FFPSign_Mask; /* tmp = -tmp; */
71 yabs = SPAdd(yabs, tmp);
73 if ( (char)yabs > (char)pio2 && (yabs & FFPMantisse_Mask) > (pio2 & FFPMantisse_Mask) )
75 yabs |= FFPSign_Mask;
76 yabs = SPAdd(pi, yabs);
78 ysquared = SPMul(yabs,yabs);
79 Res = SPMul(yabs,
80 SPAdd(sinf1,
81 SPMul(ysquared,
82 SPAdd(sinf2,
83 SPMul(ysquared,
84 SPAdd(sinf3,
85 SPMul(ysquared,
86 SPAdd(sinf4,
87 SPMul(ysquared,
88 SPAdd(sinf5,
89 SPMul(ysquared, sinf6)))))))))));
91 if ((char)fnum1 < 0 ) Res ^= FFPSign_Mask;
93 if (TRUE == intern_SPisodd(z)) Res ^= FFPSign_Mask;
95 if (0 == Res)
97 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
98 return 0;
101 if ((char)Res < 0)
103 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
106 return Res;
108 AROS_LIBFUNC_EXIT