add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / mathieeedoubtrans / ieeedptanh.c
blob9b4b714d11993c8544b0ce80368ed7aaf56f3e8b
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeedoubtrans_intern.h"
8 /*
9 FUNCTION
10 Calculate hyperbolic tangens of the IEEE double precision number
12 RESULT
13 IEEE double 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 ( e^x - e^(-x) )
31 tanh(x) = ----------------
32 ( e^x + e^(-x) )
34 tanh( |x| >= 18 ) = 1
36 HISTORY
39 AROS_LHQUAD1(double, IEEEDPTanh,
40 AROS_LHAQUAD(double, y, D0, D1),
41 struct MathIeeeDoubTransBase *, MathIeeeDoubTransBase, 12, MathIeeeDoubTrans
44 AROS_LIBFUNC_INIT
46 QUAD Res;
47 QUAD y2;
48 /* y2 = y & (IEEESPMantisse_Mask + IEEESPExponent_Mask ); */
49 Set_Value64(y2, y);
50 AND64QC
52 y2,
53 (IEEEDPMantisse_Mask_Hi + IEEEDPExponent_Mask_Hi),
54 (IEEEDPMantisse_Mask_Lo + IEEEDPExponent_Mask_Lo)
57 if ( is_geqC(y2, 0x40320000, 0x0) )
59 /*
60 tanh( x > 18 ) = 1
61 tanh( x <-18 ) = -1
63 if ( is_lessSC(y, 0x0, 0x0))
65 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
66 Set_Value64C(Res, 0xbfefffff, 0xffffffff);
68 else
70 Set_Value64C(Res, 0x3fefffff, 0xffffffff);
72 return Res;
74 /* tanh(-x) = -tanh(x) */
76 QUAD One, tmp1, tmp2;
77 Set_Value64C(One, 0x3ff00000, 0x0);
79 Res = IEEEDPExp(y2);
80 tmp1 = IEEEDPDiv(One, Res);
81 Set_Value64(tmp2, tmp1);
82 OR64QC(tmp2, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
83 Res = IEEEDPDiv
85 IEEEDPAdd(Res, tmp2),
86 IEEEDPAdd(Res, tmp1)
89 /* Result is zero */
90 if (is_eqC(Res, 0x0, 0x0) )
92 if (is_lessSC(y, 0x0, 0x0))
94 SetSR
96 Zero_Bit | Negative_Bit,
97 Zero_Bit | Negative_Bit | Overflow_Bit
100 else
102 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
104 return Res;
107 /* Argument is negative -> result is negative */
108 if ( is_lessSC(y, 0x0, 0x0))
110 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
111 OR64QC(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
112 return Res;
115 return Res;
117 AROS_LIBFUNC_EXIT