grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesptan.c
blob9c0ffd072cfdaabf5a92897d7efd9c29b4a71632
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_LH1(float, IEEESPTan,
14 /* SYNOPSIS */
15 AROS_LHA(float, y, D0),
17 /* LOCATION */
18 struct Library *, MathIeeeSingTransBase, 8, MathIeeeSingTrans)
20 /* FUNCTION
21 Calculate the tangens of a given IEEE single precision number in radians
23 INPUTS
25 RESULT
26 IEEE single precision floating point number
28 flags:
29 zero : result is zero
30 negative : result is negative
31 overflow :
33 BUGS
35 INTERNALS
37 *****************************************************************************/
39 AROS_LIBFUNC_INIT
41 LONG z,SIN,Res,ysquared,yabs,tmp;
42 yabs = y & (IEEESPMantisse_Mask + IEEESPExponent_Mask);
44 if (IEEESP_Pinfty == yabs)
46 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
47 return IEEESP_NAN;
50 z = IEEESPFloor(IEEESPDiv(yabs, pi));
51 tmp = IEEESPMul(z,pi);
52 tmp |= IEEESPSign_Mask; /* tmp = -tmp; */
53 yabs = IEEESPAdd(yabs, tmp);
54 if (yabs > pio2)
56 yabs |= IEEESPSign_Mask;
57 yabs =IEEESPAdd(pi, yabs);
58 tmp = TRUE;
60 else
62 tmp = FALSE;
65 ysquared = IEEESPMul(yabs,yabs);
66 SIN = IEEESPMul(yabs,
67 IEEESPAdd(sinf1,
68 IEEESPMul(ysquared,
69 IEEESPAdd(sinf2,
70 IEEESPMul(ysquared,
71 IEEESPAdd(sinf3,
72 IEEESPMul(ysquared,
73 IEEESPAdd(sinf4,
74 IEEESPMul(ysquared,
75 IEEESPAdd(sinf5,
76 IEEESPMul(ysquared, sinf6)))))))))));
77 /* cos: */
78 z = IEEESPAdd(cosf1,
79 IEEESPMul(ysquared,
80 IEEESPAdd(cosf2,
81 IEEESPMul(ysquared,
82 IEEESPAdd(cosf3,
83 IEEESPMul(ysquared,
84 IEEESPAdd(cosf4,
85 IEEESPMul(ysquared,
86 IEEESPAdd(cosf5,
87 IEEESPMul(ysquared, cosf6))))))))));
89 Res = IEEESPDiv(SIN, z);
91 if (y < 0 ) Res ^= IEEESPSign_Mask;
92 if (TRUE == tmp) Res ^= IEEESPSign_Mask;
94 if (0 == Res)
96 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
97 return 0;
100 if (Res < 0) SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
102 return Res;
104 AROS_LIBFUNC_EXIT