Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / mathtrans / sptanh.c
blob97414482c66d2a8fb41c2eb283f00def87d08663
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 hyperbolic tangens of the ffp number
12 RESULT
13 Motorola fast floating point number
15 flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : (not possible)
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
28 INTERNALS
29 <code>
31 ( e^x - e^(-x) )
32 tanh(x) = ----------------
33 ( e^x + e^(-x) )
35 tanh( |x| > 9 ) = 1
36 </code>
38 HISTORY
41 AROS_LH1(float, SPTanh,
42 AROS_LHA(float, fnum1, D0),
43 struct Library *, MathTransBase, 12, MathTrans
46 AROS_LIBFUNC_INIT
48 ULONG Res;
49 LONG tmp;
51 tmp = (fnum1 & FFPExponent_Mask) - 0x41;
53 if ( tmp >= 3 && (fnum1 & FFPMantisse_Mask) >= 0x90000000 )
55 /*
56 tanh( x > 9 ) = 1
57 tanh( x <-9 ) = -1
58 */
59 return (one | ( fnum1 & FFPSign_Mask ));
62 /* tanh(-x) = -tanh(x) */
63 Res = SPExp(fnum1 & (FFPMantisse_Mask + FFPExponent_Mask ));
64 Res = SPDiv
66 SPAdd(Res, SPDiv(Res, one)),
67 SPAdd(Res, (ULONG)SPDiv(Res, one) | FFPSign_Mask )
70 /* Result is zero */
71 if (0 == Res )
73 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
74 return 0;
77 /* Argument is negative -> result is negative */
78 if ( (char) fnum1 < 0)
80 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
81 return (Res | FFPSign_Mask );
84 return Res;
86 AROS_LIBFUNC_EXIT