55 * fl(1.0+2/(expm1(2*threshold)+2)) == 1.
56 *
57 * Special cases:
58 * tanhl(NaN) is NaN;
59 * only tanhl(0.0)=0.0 is exact for finite argument.
60 */
61
62 #include "libm.h"
63 #include "longdouble.h"
64
65 static const long double small = 1.0e-20L, one = 1.0, two = 2.0,
66 #ifndef lint
67 big = 1.0e+20L,
68 #endif
69 threshold = 45.0L;
70
71 long double
72 tanhl(long double x) {
73 long double t, y, z;
74 int signx;
75
76 if (isnanl(x))
77 return (x + x); /* x is NaN */
78 signx = signbitl(x);
79 t = fabsl(x);
80 z = one;
81 if (t <= threshold) {
82 if (t > one)
83 z = one - two / (expm1l(t + t) + two);
84 else if (t > small) {
85 y = expm1l(-t - t);
86 z = -y / (y + two);
87 } else {
88 #ifndef lint
89 volatile long double dummy = t + big;
90 /* inexact if t != 0 */
91 #endif
92 return (x);
93 }
94 } else if (!finitel(t))
95 return (copysignl(one, x));
96 else
97 return (signx ? -z + small * small : z - small * small);
98 return (signx ? -z : z);
99 }
|
55 * fl(1.0+2/(expm1(2*threshold)+2)) == 1.
56 *
57 * Special cases:
58 * tanhl(NaN) is NaN;
59 * only tanhl(0.0)=0.0 is exact for finite argument.
60 */
61
62 #include "libm.h"
63 #include "longdouble.h"
64
65 static const long double small = 1.0e-20L, one = 1.0, two = 2.0,
66 #ifndef lint
67 big = 1.0e+20L,
68 #endif
69 threshold = 45.0L;
70
71 long double
72 tanhl(long double x) {
73 long double t, y, z;
74 int signx;
75 volatile long double dummy;
76
77 if (isnanl(x))
78 return (x + x); /* x is NaN */
79 signx = signbitl(x);
80 t = fabsl(x);
81 z = one;
82 if (t <= threshold) {
83 if (t > one)
84 z = one - two / (expm1l(t + t) + two);
85 else if (t > small) {
86 y = expm1l(-t - t);
87 z = -y / (y + two);
88 } else {
89 #ifndef lint
90 dummy = t + big;
91 /* inexact if t != 0 */
92 #endif
93 return (x);
94 }
95 } else if (!finitel(t))
96 return (copysignl(one, x));
97 else
98 return (signx ? -z + small * small : z - small * small);
99 return (signx ? -z : z);
100 }
|