OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libm/] [math/] [sf_tanh.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/* sf_tanh.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
#include "fdlibm.h"
17
 
18
#ifdef __STDC__
19
static const float one=1.0, two=2.0, tiny = 1.0e-30;
20
#else
21
static float one=1.0, two=2.0, tiny = 1.0e-30;
22
#endif
23
 
24
#ifdef __STDC__
25
        float tanhf(float x)
26
#else
27
        float tanhf(x)
28
        float x;
29
#endif
30
{
31
        float t,z;
32
        __int32_t jx,ix;
33
 
34
        GET_FLOAT_WORD(jx,x);
35
        ix = jx&0x7fffffff;
36
 
37
    /* x is INF or NaN */
38
        if(!FLT_UWORD_IS_FINITE(ix)) {
39
            if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
40
            else       return one/x-one;    /* tanh(NaN) = NaN */
41
        }
42
 
43
    /* |x| < 22 */
44
        if (ix < 0x41b00000) {          /* |x|<22 */
45
            if (ix<0x24000000)          /* |x|<2**-55 */
46
                return x*(one+x);       /* tanh(small) = small */
47
            if (ix>=0x3f800000) {       /* |x|>=1  */
48
                t = expm1f(two*fabsf(x));
49
                z = one - two/(t+two);
50
            } else {
51
                t = expm1f(-two*fabsf(x));
52
                z= -t/(t+two);
53
            }
54
    /* |x| > 22, return +-1 */
55
        } else {
56
            z = one - tiny;             /* raised inexact flag */
57
        }
58
        return (jx>=0)? z: -z;
59
}
60
 
61
#ifdef _DOUBLE_IS_32BITS
62
 
63
#ifdef __STDC__
64
        double tanh(double x)
65
#else
66
        double tanh(x)
67
        double x;
68
#endif
69
{
70
        return (double) tanhf((float) x);
71
}
72
 
73
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.