1 /* s_tanhl.c -- __float128 version of s_tanh.c.
2 * Conversion to __float128 by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
14 * ====================================================
17 /* Changes for 128-bit __float128 contributed by
18 Stephen L. Moshier <moshier@na-net.ornl.gov> */
21 * Return the Hyperbolic Tangent of x
26 * 0. tanhl(x) is defined to be -----------
29 * 1. reduce x to non-negative by tanhl(-x) = -tanhl(x).
30 * 2. 0 <= x <= 2**-57 : tanhl(x) := x*(one+x)
32 * 2**-57 < x <= 1 : tanhl(x) := -----; t = expm1l(-2x)
35 * 1 <= x <= 40.0 : tanhl(x) := 1- ----- ; t=expm1l(2x)
37 * 40.0 < x <= INF : tanhl(x) := 1.
41 * only tanhl(0)=0 is exact for finite argument.
44 #include "quadmath-imp.h"
46 static const __float128 one
= 1.0Q
, two
= 2.0Q
, tiny
= 1.0e-4900Q
;
62 /* for NaN it's not important which branch: tanhl(NaN) = NaN */
64 return one
/ x
- one
; /* tanhl(-inf)= -1; */
66 return one
/ x
+ one
; /* tanhl(+inf)=+1 */
73 return x
; /* x == +- 0 */
74 if (ix
< 0x3fc60000) /* |x| < 2^-57 */
76 math_check_force_underflow (x
);
77 return x
* (one
+ tiny
); /* tanh(small) = small */
79 u
.words32
.w0
= ix
; /* Absolute value of x. */
82 t
= expm1q (two
* u
.value
);
83 z
= one
- two
/ (t
+ two
);
87 t
= expm1q (-two
* u
.value
);
90 /* |x| > 40, return +-1 */
94 z
= one
- tiny
; /* raised inexact flag */
96 return (jx
& 0x80000000) ? -z
: z
;