an update to previous patch fixes nearly all remaining constants used in the math...
[AROS.git] / compiler / stdc / math / s_tanhf.c
blob8bd5685a130ad5f19d5735107bafe2eeb0191d2a
1 /* s_tanhf.c -- float version of s_tanh.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
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
12 * is preserved.
13 * ====================================================
16 #ifndef lint
17 static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanhf.c,v 1.9 2008/02/22 02:30:36 das Exp $";
18 #endif
20 #include "math.h"
21 #include "math_private.h"
23 static const volatile float tiny __attribute__ ((__section__(".rodata"))) = 1.0e-30;
24 static const float one=1.0, two=2.0, huge = 1.0e30;
26 float
27 tanhf(float x)
29 float t,z;
30 int32_t jx,ix;
32 GET_FLOAT_WORD(jx,x);
33 ix = jx&0x7fffffff;
35 /* x is INF or NaN */
36 if(ix>=0x7f800000) {
37 if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
38 else return one/x-one; /* tanh(NaN) = NaN */
41 /* |x| < 9 */
42 if (ix < 0x41100000) { /* |x|<9 */
43 if (ix<0x39800000) { /* |x|<2**-12 */
44 if(huge+x>one) return x; /* tanh(tiny) = tiny with inexact */
46 if (ix>=0x3f800000) { /* |x|>=1 */
47 t = expm1f(two*fabsf(x));
48 z = one - two/(t+two);
49 } else {
50 t = expm1f(-two*fabsf(x));
51 z= -t/(t+two);
53 /* |x| >= 9, return +-1 */
54 } else {
55 z = one - tiny; /* raise inexact flag */
57 return (jx>=0)? z: -z;