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 * ====================================================
27 GET_FLOAT_WORD(jx, x);
31 if(ix >= 0x7f800000) {
33 return 1.0f/x + 1.0f; /* tanh(+-inf)=+-1 */
35 return 1.0f/x - 1.0f; /* tanh(NaN) = NaN */
38 if (ix < 0x41100000) { /* |x| < 9 */
39 if (ix < 0x39800000) { /* |x| < 2**-12 */
40 /* tanh(tiny) = tiny with inexact */
44 if (ix >= 0x3f800000) { /* |x|>=1 */
45 t = expm1f(2.0f*fabsf(x));
46 z = 1.0f - 2.0f/(t+2.0f);
48 t = expm1f(-2.0f*fabsf(x));
51 } else { /* |x| >= 9, return +-1 */
52 z = 1.0f - tiny; /* raise inexact */
54 return jx >= 0 ? z : -z;