Merge branch 'vendor/EXPAT'
[dragonfly.git] / lib / libm / 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
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  *
15  * $NetBSD: s_tanhf.c,v 1.7 2002/05/26 22:01:59 wiz Exp $
16  * $DragonFly: src/lib/libm/src/s_tanhf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $
17  */
18
19 #include <math.h>
20 #include "math_private.h"
21
22 static const float one=1.0, two=2.0, tiny = 1.0e-30;
23
24 float
25 tanhf(float x)
26 {
27         float t,z;
28         int32_t jx,ix;
29
30         GET_FLOAT_WORD(jx,x);
31         ix = jx&0x7fffffff;
32
33     /* x is INF or NaN */
34         if(ix>=0x7f800000) {
35             if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
36             else       return one/x-one;    /* tanh(NaN) = NaN */
37         }
38
39     /* |x| < 22 */
40         if (ix < 0x41b00000) {          /* |x|<22 */
41             if (ix<0x24000000)          /* |x|<2**-55 */
42                 return x*(one+x);       /* tanh(small) = small */
43             if (ix>=0x3f800000) {       /* |x|>=1  */
44                 t = expm1f(two*fabsf(x));
45                 z = one - two/(t+two);
46             } else {
47                 t = expm1f(-two*fabsf(x));
48                 z= -t/(t+two);
49             }
50     /* |x| > 22, return +-1 */
51         } else {
52             z = one - tiny;             /* raised inexact flag */
53         }
54         return (jx>=0)? z: -z;
55 }