Blame sysdeps/ieee754/flt-32/s_tanhf.c

Packit 6c4009
/* s_tanhf.c -- float version of s_tanh.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#if defined(LIBM_SCCS) && !defined(lint)
Packit 6c4009
static char rcsid[] = "$NetBSD: s_tanhf.c,v 1.4 1995/05/10 20:48:24 jtc Exp $";
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#include <float.h>
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include <math-underflow.h>
Packit 6c4009
#include <libm-alias-float.h>
Packit 6c4009
Packit 6c4009
static const float one=1.0, two=2.0, tiny = 1.0e-30;
Packit 6c4009
Packit 6c4009
float __tanhf(float x)
Packit 6c4009
{
Packit 6c4009
	float t,z;
Packit 6c4009
	int32_t jx,ix;
Packit 6c4009
Packit 6c4009
	GET_FLOAT_WORD(jx,x);
Packit 6c4009
	ix = jx&0x7fffffff;
Packit 6c4009
Packit 6c4009
    /* x is INF or NaN */
Packit 6c4009
	if(ix>=0x7f800000) {
Packit 6c4009
	    if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
Packit 6c4009
	    else       return one/x-one;    /* tanh(NaN) = NaN */
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
    /* |x| < 22 */
Packit 6c4009
	if (ix < 0x41b00000) {		/* |x|<22 */
Packit 6c4009
	    if (ix == 0)
Packit 6c4009
		return x;		/* x == +-0 */
Packit 6c4009
	    if (ix<0x24000000) 		/* |x|<2**-55 */
Packit 6c4009
	      {
Packit 6c4009
		math_check_force_underflow (x);
Packit 6c4009
		return x*(one+x);    	/* tanh(small) = small */
Packit 6c4009
	      }
Packit 6c4009
	    if (ix>=0x3f800000) {	/* |x|>=1  */
Packit 6c4009
		t = __expm1f(two*fabsf(x));
Packit 6c4009
		z = one - two/(t+two);
Packit 6c4009
	    } else {
Packit 6c4009
	        t = __expm1f(-two*fabsf(x));
Packit 6c4009
	        z= -t/(t+two);
Packit 6c4009
	    }
Packit 6c4009
    /* |x| > 22, return +-1 */
Packit 6c4009
	} else {
Packit 6c4009
	    z = one - tiny;		/* raised inexact flag */
Packit 6c4009
	}
Packit 6c4009
	return (jx>=0)? z: -z;
Packit 6c4009
}
Packit 6c4009
libm_alias_float (__tanh, tanh)