Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / mathtrans / sptan.c
blobe8e979c78994e8c98b627cdcc403fc4ec3225f7c
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 tangens 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 :
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
28 INTERNALS
30 HISTORY
33 AROS_LH1(float, SPTan,
34 AROS_LHA(float, fnum1, D0),
35 struct Library *, MathTransBase, 8, MathTrans
38 AROS_LIBFUNC_INIT
40 LONG z,SIN,Res,ysquared,yabs,tmp;
41 yabs = fnum1 & (FFPMantisse_Mask + FFPExponent_Mask);
43 if ((LONG)FFP_Pinfty == yabs)
45 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
46 return FFP_NAN;
49 z = SPFloor(SPDiv(pi, yabs));
50 tmp = SPMul(z,pi);
51 tmp |= FFPSign_Mask; /* tmp = -tmp; */
52 yabs = SPAdd(yabs, tmp);
54 if ( (char)yabs > (char)pio2 && (yabs & FFPMantisse_Mask) > (pio2 & FFPMantisse_Mask) )
56 yabs |= FFPSign_Mask;
57 yabs =SPAdd(pi, yabs);
58 tmp = TRUE;
60 else
62 tmp = FALSE;
65 ysquared = SPMul(yabs,yabs);
66 SIN = SPMul(yabs,
67 SPAdd(sinf1,
68 SPMul(ysquared,
69 SPAdd(sinf2,
70 SPMul(ysquared,
71 SPAdd(sinf3,
72 SPMul(ysquared,
73 SPAdd(sinf4,
74 SPMul(ysquared,
75 SPAdd(sinf5,
76 SPMul(ysquared, sinf6)))))))))));
77 /* cos */
78 z = SPAdd(cosf1,
79 SPMul(ysquared,
80 SPAdd(cosf2,
81 SPMul(ysquared,
82 SPAdd(cosf3,
83 SPMul(ysquared,
84 SPAdd(cosf4,
85 SPMul(ysquared,
86 SPAdd(cosf5,
87 SPMul(ysquared, cosf6))))))))));
89 Res = SPDiv(z, SIN);
91 if ((char)fnum1 < 0 ) Res ^= FFPSign_Mask;
92 if (TRUE == tmp) 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