Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 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
 
16
#ifndef lint
17
static char rcsid[] = "$\Id: s_tanhf.c,v 1.2 1995/05/30 05:50:36 rgrimes Exp $";
18
#endif
19
 
20
#include "math.h"
21
#include "math_private.h"
22
 
23
#ifdef __STDC__
24
static const float one=1.0, two=2.0, tiny = 1.0e-30;
25
#else
26
static float one=1.0, two=2.0, tiny = 1.0e-30;
27
#endif
28
 
29
#ifdef __STDC__
30
        float tanhf(float x)
31
#else
32
        float tanhf(x)
33
        float x;
34
#endif
35
{
36
        float t,z;
37
        int32_t jx,ix;
38
 
39
        GET_FLOAT_WORD(jx,x);
40
        ix = jx&0x7fffffff;
41
 
42
    /* x is INF or NaN */
43
        if(ix>=0x7f800000) {
44
            if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
45
            else       return one/x-one;    /* tanh(NaN) = NaN */
46
        }
47
 
48
    /* |x| < 22 */
49
        if (ix < 0x41b00000) {          /* |x|<22 */
50
            if (ix<0x24000000)          /* |x|<2**-55 */
51
                return x*(one+x);       /* tanh(small) = small */
52
            if (ix>=0x3f800000) {       /* |x|>=1  */
53
                t = expm1f(two*fabsf(x));
54
                z = one - two/(t+two);
55
            } else {
56
                t = expm1f(-two*fabsf(x));
57
                z= -t/(t+two);
58
            }
59
    /* |x| > 22, return +-1 */
60
        } else {
61
            z = one - tiny;             /* raised inexact flag */
62
        }
63
        return (jx>=0)? z: -z;
64
}