1 /* s_tanhf.c -- float version of s_tanh.c.
2 * 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 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid
[] = "$NetBSD: s_tanhf.c,v 1.4 1995/05/10 20:48:24 jtc Exp $";
21 #include "math_private.h"
24 static const float one
=1.0, two
=2.0, tiny
= 1.0e-30;
26 static float one
=1.0, two
=2.0, tiny
= 1.0e-30;
30 float __tanhf(float x
)
44 if (jx
>=0) return one
/x
+one
; /* tanh(+-inf)=+-1 */
45 else return one
/x
-one
; /* tanh(NaN) = NaN */
49 if (ix
< 0x41b00000) { /* |x|<22 */
51 return x
; /* x == +-0 */
52 if (ix
<0x24000000) /* |x|<2**-55 */
53 return x
*(one
+x
); /* tanh(small) = small */
54 if (ix
>=0x3f800000) { /* |x|>=1 */
55 t
= __expm1f(two
*fabsf(x
));
56 z
= one
- two
/(t
+two
);
58 t
= __expm1f(-two
*fabsf(x
));
61 /* |x| > 22, return +-1 */
63 z
= one
- tiny
; /* raised inexact flag */
65 return (jx
>=0)? z
: -z
;
67 weak_alias (__tanhf
, tanhf
)