be051b9d894abad147cacb93088530d2d589e029
[dragonfly.git] / lib / msun / src / s_tanhf.c
1 /* s_tanhf.c -- float version of s_tanh.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  *
4  * $FreeBSD: src/lib/msun/src/s_tanhf.c,v 1.5 1999/08/28 00:06:56 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/s_tanhf.c,v 1.2 2003/06/17 04:26:53 dillon Exp $
6  */
7
8 /*
9  * ====================================================
10  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11  *
12  * Developed at SunPro, a Sun Microsystems, Inc. business.
13  * Permission to use, copy, modify, and distribute this
14  * software is freely granted, provided that this notice
15  * is preserved.
16  * ====================================================
17  */
18
19 #include "math.h"
20 #include "math_private.h"
21
22 #ifdef __STDC__
23 static const float one=1.0, two=2.0, tiny = 1.0e-30;
24 #else
25 static float one=1.0, two=2.0, tiny = 1.0e-30;
26 #endif
27
28 #ifdef __STDC__
29         float tanhf(float x)
30 #else
31         float tanhf(x)
32         float x;
33 #endif
34 {
35         float t,z;
36         int32_t jx,ix;
37
38         GET_FLOAT_WORD(jx,x);
39         ix = jx&0x7fffffff;
40
41     /* x is INF or NaN */
42         if(ix>=0x7f800000) {
43             if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
44             else       return one/x-one;    /* tanh(NaN) = NaN */
45         }
46
47     /* |x| < 22 */
48         if (ix < 0x41b00000) {          /* |x|<22 */
49             if (ix<0x24000000)          /* |x|<2**-55 */
50                 return x*(one+x);       /* tanh(small) = small */
51             if (ix>=0x3f800000) {       /* |x|>=1  */
52                 t = expm1f(two*fabsf(x));
53                 z = one - two/(t+two);
54             } else {
55                 t = expm1f(-two*fabsf(x));
56                 z= -t/(t+two);
57             }
58     /* |x| > 22, return +-1 */
59         } else {
60             z = one - tiny;             /* raised inexact flag */
61         }
62         return (jx>=0)? z: -z;
63 }