grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathtrans / spsin.c
blobfd2acb22f8604a911a688f4943441d3ce48731b6
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathtrans_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH1(float, SPSin,
14 /* SYNOPSIS */
15 AROS_LHA(float, fnum1, D0),
17 /* LOCATION */
18 struct Library *, MathTransBase, 6, MathTrans)
20 /* FUNCTION
21 Calculate the sine of a given FFP number in radians
23 INPUTS
25 RESULT
26 Motorola fast floating point number
28 flags:
29 zero : result is zero
30 negative : result is negative
31 overflow : 0
33 BUGS
35 INTERNALS
36 Algorithm for Calculation of sin(y):
38 z = floor ( |y| / pi );
39 y_1 = |y| - z * pi; => 0 <= y_1 < pi
41 if (y_1 > pi/2 ) then y_1 = pi - y_1;
43 => 0 <= y_1 < pi/2
45 Res = y - y^3/3! + y^5/5! - y^7/7! + y^9/9! - y^11/11! =
46 = y(1+y^2(-1/3!+y^2(1/5!+y^2(-1/7!+y^2(1/9!-1/11!y^2)))));
48 if (y < 0)
49 Res = -Res;
51 if (z was an odd number)
52 Res = -Res;
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
58 LONG z,Res,ysquared,yabs,tmp;
59 yabs = fnum1 & (FFPMantisse_Mask + FFPExponent_Mask);
61 if ((LONG)FFP_Pinfty == yabs)
63 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
64 return FFP_NAN;
67 z = SPFloor(SPDiv(pi, yabs));
68 tmp = SPMul(z,pi);
69 tmp |= FFPSign_Mask; /* tmp = -tmp; */
70 yabs = SPAdd(yabs, tmp);
72 if ( (char)yabs > (char)pio2 && (yabs & FFPMantisse_Mask) > (pio2 & FFPMantisse_Mask) )
74 yabs |= FFPSign_Mask;
75 yabs = SPAdd(pi, yabs);
77 ysquared = SPMul(yabs,yabs);
78 Res = SPMul(yabs,
79 SPAdd(sinf1,
80 SPMul(ysquared,
81 SPAdd(sinf2,
82 SPMul(ysquared,
83 SPAdd(sinf3,
84 SPMul(ysquared,
85 SPAdd(sinf4,
86 SPMul(ysquared,
87 SPAdd(sinf5,
88 SPMul(ysquared, sinf6)))))))))));
90 if ((char)fnum1 < 0 ) Res ^= FFPSign_Mask;
92 if (TRUE == intern_SPisodd(z)) Res ^= FFPSign_Mask;
94 if (0 == Res)
96 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
97 return 0;
100 if ((char)Res < 0)
102 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
105 return Res;
107 AROS_LIBFUNC_EXIT