Subversion Repositories Kolibri OS

Rev

Rev 1906 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1906 Rev 3362
Line -... Line 1...
-
 
1
/* @(#)s_tanh.c 5.1 93/09/24 */
1
/* @(#)s_tanh.c 5.1 93/09/24 */
2
/*
2
/*
3
 * ====================================================
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Line 8... Line 9...
8
 * software is freely granted, provided that this notice
9
 * is preserved.
9
 * is preserved.
10
 * ====================================================
10
 * ====================================================
11
 */
11
 */
12
 
Line -... Line 13...
-
 
13
/*
-
 
14
 
-
 
15
FUNCTION
-
 
16
        <>, <>---hyperbolic tangent
-
 
17
 
-
 
18
INDEX
-
 
19
tanh
-
 
20
INDEX
-
 
21
tanhf
-
 
22
 
-
 
23
ANSI_SYNOPSIS
-
 
24
        #include 
-
 
25
        double tanh(double <[x]>);
-
 
26
        float tanhf(float <[x]>);
-
 
27
 
-
 
28
TRAD_SYNOPSIS
-
 
29
        #include 
-
 
30
        double tanh(<[x]>)
-
 
31
        double <[x]>;
-
 
32
 
-
 
33
        float tanhf(<[x]>)
-
 
34
        float <[x]>;
-
 
35
 
-
 
36
 
-
 
37
DESCRIPTION
-
 
38
 
-
 
39
<> computes the hyperbolic tangent of
-
 
40
the argument <[x]>.  Angles are specified in radians.  
-
 
41
 
-
 
42
<)>> is defined as 
-
 
43
. sinh(<[x]>)/cosh(<[x]>)
-
 
44
	
-
 
45
<> is identical, save that it takes and returns <> values.
-
 
46
 
-
 
47
RETURNS
-
 
48
The hyperbolic tangent of <[x]> is returned.
-
 
49
 
-
 
50
PORTABILITY
-
 
51
<> is ANSI C.  <> is an extension.
-
 
52
 
-
 
53
*/
Line 12... Line 54...
12
 
54
 
13
 
55
/* Tanh(x)
14
/* Tanh(x)
56
 * Return the Hyperbolic Tangent of x
15
 * Return the Hyperbolic Tangent of x
57
 *
Line 33... Line 75...
33
 * Special cases:
75
 *	tanh(NaN) is NaN;
34
 *	tanh(NaN) is NaN;
76
 *	only tanh(0)=0 is exact for finite argument.
35
 *	only tanh(0)=0 is exact for finite argument.
77
 */
36
 */
78
 
Line 37... Line -...
37
 
-
 
38
#include 
79
#include "fdlibm.h"
Line -... Line 80...
-
 
80
 
-
 
81
#ifndef _DOUBLE_IS_32BITS
39
#include "fdlibm.h"
82
 
40
 
83
#ifdef __STDC__
41
#ifdef __STDC__
84
static const double one=1.0, two=2.0, tiny = 1.0e-300;
42
static const double one=1.0, two=2.0, tiny = 1.0e-300;
85
#else
43
#else
86
static double one=1.0, two=2.0, tiny = 1.0e-300;
Line -... Line 87...
-
 
87
#endif
44
static double one=1.0, two=2.0, tiny = 1.0e-300;
88
 
-
 
89
#ifdef __STDC__
-
 
90
	double tanh(double x)
-
 
91
#else
-
 
92
	double tanh(x)
45
#endif
93
	double x;
46
 
94
#endif
47
double tanh(double x)
95
{
Line 48... Line 96...
48
{
96
	double t,z;
49
	double t,z;
97
	__int32_t jx,ix;
50
    int jx,ix,lx;
98
 
Line 51... Line 99...
51
 
99
    /* High word of |x|. */
52
    /* High word of |x|. */
100
	GET_HIGH_WORD(jx,x);
53
	EXTRACT_WORDS(jx,lx,x);
101
	ix = jx&0x7fffffff;
54
	ix = jx&0x7fffffff;
102
 
55
 
103
    /* x is INF or NaN */
Line 56... Line 104...
56
    /* x is INF or NaN */
104
	if(ix>=0x7ff00000) { 
57
	if(ix>=0x7ff00000) {
105
	    if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
58
	    if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
-
 
59
	    else       return one/x-one;    /* tanh(NaN) = NaN */
-
 
60
	}
106
	    else       return one/x-one;    /* tanh(NaN) = NaN */
61
 
107
	}
62
    /* |x| < 22 */
108
 
63
	if (ix < 0x40360000) {		/* |x|<22 */
109
    /* |x| < 22 */
64
	    if ((ix | lx) == 0)
110
	if (ix < 0x40360000) {		/* |x|<22 */
65
		return x;		/* x == +-0 */
111
	    if (ix<0x3c800000) 		/* |x|<2**-55 */
66
	    if (ix<0x3c800000) 		/* |x|<2**-55 */
112
		return x*(one+x);    	/* tanh(small) = small */
67
		return x*(one+x);    	/* tanh(small) = small */
113
	    if (ix>=0x3ff00000) {	/* |x|>=1  */
68
	    if (ix>=0x3ff00000) {	/* |x|>=1  */
114
		t = expm1(two*fabs(x));
69
		t = __expm1(two*fabs(x));
115
		z = one - two/(t+two);
70
		z = one - two/(t+two);
116
	    } else {
71
	    } else {
117
	        t = expm1(-two*fabs(x));
72
	        t = __expm1(-two*fabs(x));
118
	        z= -t/(t+two);
73
	        z= -t/(t+two);
119
	    }
74
	    }
120
    /* |x| > 22, return +-1 */
-
 
121
	} else {
-
 
122
	    z = one - tiny;		/* raised inexact flag */