1 /* s_tanhl.c -- long double version of s_tanh.c.
2 * Conversion to long double 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 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid
[] = "$NetBSD: $";
22 * Return the Hyperbolic Tangent of x
27 * 0. tanhl(x) is defined to be -----------
30 * 1. reduce x to non-negative by tanhl(-x) = -tanhl(x).
31 * 2. 0 <= x <= 2**-55 : tanhl(x) := x*(one+x)
33 * 2**-55 < x <= 1 : tanhl(x) := -----; t = expm1l(-2x)
36 * 1 <= x <= 23.0 : tanhl(x) := 1- ----- ; t=expm1l(2x)
38 * 23.0 < x <= INF : tanhl(x) := 1.
42 * only tanhl(0)=0 is exact for finite argument.
46 #include "math_private.h"
49 static const long double one
=1.0, two
=2.0, tiny
= 1.0e-4900L;
51 static long double one
=1.0, two
=2.0, tiny
= 1.0e-4900L;
55 long double __tanhl(long double x
)
57 long double __tanhl(x
)
65 /* High word of |x|. */
66 GET_LDOUBLE_WORDS(se
,j0
,j1
,x
);
71 /* for NaN it's not important which branch: tanhl(NaN) = NaN */
72 if (se
&0x8000) return one
/x
-one
; /* tanhl(-inf)= -1; */
73 else return one
/x
+one
; /* tanhl(+inf)=+1 */
77 if (ix
< 0x4003 || (ix
== 0x4003 && j0
< 0xb8000000u
)) {/* |x|<23 */
79 return x
; /* x == +- 0 */
80 if (ix
<0x3fc8) /* |x|<2**-55 */
81 return x
*(one
+tiny
); /* tanh(small) = small */
82 if (ix
>=0x3fff) { /* |x|>=1 */
83 t
= __expm1l(two
*fabsl(x
));
84 z
= one
- two
/(t
+two
);
86 t
= __expm1l(-two
*fabsl(x
));
89 /* |x| > 23, return +-1 */
91 z
= one
- tiny
; /* raised inexact flag */
93 return (se
&0x8000)? -z
: z
;
95 weak_alias (__tanhl
, tanhl
)