s_tanhf.c revision 8870
12116Sjkh/* s_tanhf.c -- float version of s_tanh.c. 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 32116Sjkh */ 42116Sjkh 52116Sjkh/* 62116Sjkh * ==================================================== 72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 82116Sjkh * 92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 102116Sjkh * Permission to use, copy, modify, and distribute this 118870Srgrimes * software is freely granted, provided that this notice 122116Sjkh * is preserved. 132116Sjkh * ==================================================== 142116Sjkh */ 152116Sjkh 162116Sjkh#ifndef lint 178870Srgrimesstatic char rcsid[] = "$Id: s_tanhf.c,v 1.1.1.1 1994/08/19 09:39:59 jkh Exp $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 222116Sjkh 232116Sjkh#ifdef __STDC__ 242116Sjkhstatic const float one=1.0, two=2.0, tiny = 1.0e-30; 252116Sjkh#else 262116Sjkhstatic float one=1.0, two=2.0, tiny = 1.0e-30; 272116Sjkh#endif 282116Sjkh 292116Sjkh#ifdef __STDC__ 302116Sjkh float tanhf(float x) 312116Sjkh#else 322116Sjkh float tanhf(x) 332116Sjkh float x; 342116Sjkh#endif 352116Sjkh{ 362116Sjkh float t,z; 372116Sjkh int32_t jx,ix; 382116Sjkh 392116Sjkh GET_FLOAT_WORD(jx,x); 402116Sjkh ix = jx&0x7fffffff; 412116Sjkh 422116Sjkh /* x is INF or NaN */ 438870Srgrimes if(ix>=0x7f800000) { 442116Sjkh if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */ 452116Sjkh else return one/x-one; /* tanh(NaN) = NaN */ 462116Sjkh } 472116Sjkh 482116Sjkh /* |x| < 22 */ 492116Sjkh if (ix < 0x41b00000) { /* |x|<22 */ 502116Sjkh if (ix<0x24000000) /* |x|<2**-55 */ 512116Sjkh return x*(one+x); /* tanh(small) = small */ 522116Sjkh if (ix>=0x3f800000) { /* |x|>=1 */ 532116Sjkh t = expm1f(two*fabsf(x)); 542116Sjkh z = one - two/(t+two); 552116Sjkh } else { 562116Sjkh t = expm1f(-two*fabsf(x)); 572116Sjkh z= -t/(t+two); 582116Sjkh } 592116Sjkh /* |x| > 22, return +-1 */ 602116Sjkh } else { 612116Sjkh z = one - tiny; /* raised inexact flag */ 622116Sjkh } 632116Sjkh return (jx>=0)? z: -z; 642116Sjkh} 65