1 /* origin: FreeBSD /usr/src/lib/msun/src/s_tanhf.c */
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
18 static const float one = 1.0, two = 2.0, tiny = 1.0e-30, huge = 1.0e30;
25 GET_FLOAT_WORD(jx, x);
29 if(ix >= 0x7f800000) {
31 return one/x + one; /* tanh(+-inf)=+-1 */
33 return one/x - one; /* tanh(NaN) = NaN */
36 if (ix < 0x41100000) { /* |x| < 9 */
37 if (ix < 0x39800000) { /* |x| < 2**-12 */
38 /* tanh(tiny) = tiny with inexact */
42 if (ix >= 0x3f800000) { /* |x|>=1 */
43 t = expm1f(two*fabsf(x));
44 z = one - two/(t+two);
46 t = expm1f(-two*fabsf(x));
49 } else { /* |x| >= 9, return +-1 */
50 z = one - tiny; /* raise inexact */
52 return jx >= 0 ? z : -z;