vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

s_tanhf.c (1436B)


      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 #ifndef lint
     17 static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanhf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
     18 #endif
     19 
     20 #include "math.h"
     21 #include "math_private.h"
     22 
     23 static const float one=1.0, two=2.0, tiny = 1.0e-30;
     24 
     25 float
     26 tanhf(float x)
     27 {
     28 	float t,z;
     29 	int32_t jx,ix;
     30 
     31 	GET_FLOAT_WORD(jx,x);
     32 	ix = jx&0x7fffffff;
     33 
     34     /* x is INF or NaN */
     35 	if(ix>=0x7f800000) {
     36 	    if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
     37 	    else       return one/x-one;    /* tanh(NaN) = NaN */
     38 	}
     39 
     40     /* |x| < 22 */
     41 	if (ix < 0x41b00000) {		/* |x|<22 */
     42 	    if (ix<0x24000000) 		/* |x|<2**-55 */
     43 		return x*(one+x);    	/* tanh(small) = small */
     44 	    if (ix>=0x3f800000) {	/* |x|>=1  */
     45 		t = expm1f(two*fabsf(x));
     46 		z = one - two/(t+two);
     47 	    } else {
     48 	        t = expm1f(-two*fabsf(x));
     49 	        z= -t/(t+two);
     50 	    }
     51     /* |x| > 22, return +-1 */
     52 	} else {
     53 	    z = one - tiny;		/* raised inexact flag */
     54 	}
     55 	return (jx>=0)? z: -z;
     56 }