Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesptanh.c
blob39fb0e971afe4de41b952bf26cceffc56ee8da76
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingtrans_intern.h"
8 /*
9 FUNCTION
10 Calculate hyperbolic tangens of the IEEE single precision number
12 RESULT
13 IEEE single precision 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
30 <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, IEEESPTanh,
42 AROS_LHA(float, y, D0),
43 struct Library *, MathIeeeSingTransBase, 12, MathIeeeSingTrans
46 AROS_LIBFUNC_INIT
48 LONG Res;
49 LONG y2 = y & (IEEESPMantisse_Mask + IEEESPExponent_Mask );
50 LONG tmp;
52 if ( y2 >= 0x41100000 )
53 /*
54 tanh( x > 9 ) = 1
55 tanh( x <-9 ) = -1
57 return (one | ( y & IEEESPSign_Mask ));
59 /* tanh(-x) = -tanh(x) */
60 Res = IEEESPExp(y2);
61 tmp = IEEESPDiv(one, Res);
62 Res = IEEESPDiv
64 IEEESPAdd(Res, (tmp | IEEESPSign_Mask) ),
65 IEEESPAdd(Res, tmp)
68 /* Result is zero */
69 if (0 == Res )
71 if (y < 0)
73 SetSR(Zero_Bit | Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
75 else
77 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
80 return (y & IEEESPSign_Mask);
83 /* Argument is negative -> result is negative */
84 if ( y < 0)
86 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
87 return (Res | IEEESPSign_Mask );
90 return Res;
92 AROS_LIBFUNC_EXIT