1 /* s_tanhl.c -- long double version of s_tanh.c.
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 * Developed at SunPro, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
12 * ====================================================
16 * Return the Hyperbolic Tangent of x
21 * 0. tanhl(x) is defined to be -----------
24 * 1. reduce x to non-negative by tanhl(-x) = -tanhl(x).
25 * 2. 0 <= x <= 2**-57 : tanhl(x) := x*(one+x)
27 * 2**-57 < x <= 1 : tanhl(x) := -----; t = expm1l(-2x)
30 * 1 <= x <= 40.0 : tanhl(x) := 1- ----- ; t=expm1l(2x)
32 * 40.0 < x <= INF : tanhl(x) := 1.
36 * only tanhl(0)=0 is exact for finite argument.
41 #include <math_private.h>
42 #include <math-underflow.h>
43 #include <libm-alias-ldouble.h>
45 static const _Float128 one
= 1.0, two
= 2.0, tiny
= L(1.0e-4900);
52 ieee854_long_double_shape_type u
;
61 /* for NaN it's not important which branch: tanhl(NaN) = NaN */
63 return one
/ x
- one
; /* tanhl(-inf)= -1; */
65 return one
/ x
+ one
; /* tanhl(+inf)=+1 */
72 return x
; /* x == +- 0 */
73 if (ix
< 0x3fc60000) /* |x| < 2^-57 */
75 math_check_force_underflow (x
);
76 return x
* (one
+ tiny
); /* tanh(small) = small */
78 u
.parts32
.w0
= ix
; /* Absolute value of x. */
81 t
= __expm1l (two
* u
.value
);
82 z
= one
- two
/ (t
+ two
);
86 t
= __expm1l (-two
* u
.value
);
89 /* |x| > 40, return +-1 */
93 z
= one
- tiny
; /* raised inexact flag */
95 return (jx
& 0x80000000) ? -z
: z
;
97 libm_alias_ldouble (__tanh
, tanh
)