revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesptanh.c
blob3fd7feb442ffdcce871f92bc3ad772abaddf8e83
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, IEEESPTanh,
14 /* SYNOPSIS */
15 AROS_LHA(float, y, D0),
17 /* LOCATION */
18 struct Library *, MathIeeeSingTransBase, 12, MathIeeeSingTrans)
20 /* FUNCTION
21 Calculate hyperbolic tangens of the IEEE single precision number
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 : (not possible)
33 BUGS
35 INTERNALS
37 *****************************************************************************/
39 AROS_LIBFUNC_INIT
41 LONG Res;
42 LONG y2 = y & (IEEESPMantisse_Mask + IEEESPExponent_Mask );
43 LONG tmp;
45 if ( y2 >= 0x41100000 )
46 /*
47 tanh( x > 9 ) = 1
48 tanh( x <-9 ) = -1
50 return (one | ( y & IEEESPSign_Mask ));
52 /* tanh(-x) = -tanh(x) */
53 Res = IEEESPExp(y2);
54 tmp = IEEESPDiv(one, Res);
55 Res = IEEESPDiv
57 IEEESPAdd(Res, (tmp | IEEESPSign_Mask) ),
58 IEEESPAdd(Res, tmp)
61 /* Result is zero */
62 if (0 == Res )
64 if (y < 0)
66 SetSR(Zero_Bit | Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
68 else
70 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
73 return (y & IEEESPSign_Mask);
76 /* Argument is negative -> result is negative */
77 if ( y < 0)
79 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
80 return (Res | IEEESPSign_Mask );
83 return Res;
85 AROS_LIBFUNC_EXIT