1/* s_tanhf.c -- float version of s_tanh.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
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
12 * is preserved.
13 * ====================================================
14 */
15
16#if defined(LIBM_SCCS) && !defined(lint)
17static char rcsid[] = "$NetBSD: s_tanhf.c,v 1.4 1995/05/10 20:48:24 jtc Exp $";
18#endif
19
20#include <float.h>
21#include <math.h>
22#include <math_private.h>
23#include <math-underflow.h>
24#include <libm-alias-float.h>
25
26static const float one=1.0, two=2.0, tiny = 1.0e-30;
27
28float __tanhf(float x)
29{
30 float t,z;
31 int32_t jx,ix;
32
33 GET_FLOAT_WORD(jx,x);
34 ix = jx&0x7fffffff;
35
36 /* x is INF or NaN */
37 if(ix>=0x7f800000) {
38 if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
39 else return one/x-one; /* tanh(NaN) = NaN */
40 }
41
42 /* |x| < 22 */
43 if (ix < 0x41b00000) { /* |x|<22 */
44 if (ix == 0)
45 return x; /* x == +-0 */
46 if (ix<0x24000000) /* |x|<2**-55 */
47 {
48 math_check_force_underflow (x);
49 return x*(one+x); /* tanh(small) = small */
50 }
51 if (ix>=0x3f800000) { /* |x|>=1 */
52 t = __expm1f(two*fabsf(x));
53 z = one - two/(t+two);
54 } else {
55 t = __expm1f(-two*fabsf(x));
56 z= -t/(t+two);
57 }
58 /* |x| > 22, return +-1 */
59 } else {
60 z = one - tiny; /* raised inexact flag */
61 }
62 return (jx>=0)? z: -z;
63}
64libm_alias_float (__tanh, tanh)
65