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

Packit 6c4009
/* e_coshf.c -- float version of e_cosh.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Packit 6c4009
 * Optimizations by Ulrich Drepper <drepper@gmail.com>, 2011
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
#include <math.h>
Packit 6c4009
#include <math-narrow-eval.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
static const float huge = 1.0e30;
Packit 6c4009
static const float one = 1.0, half=0.5;
Packit 6c4009
Packit 6c4009
float
Packit 6c4009
__ieee754_coshf (float x)
Packit 6c4009
{
Packit 6c4009
	float t,w;
Packit 6c4009
	int32_t ix;
Packit 6c4009
Packit 6c4009
	GET_FLOAT_WORD(ix,x);
Packit 6c4009
	ix &= 0x7fffffff;
Packit 6c4009
Packit 6c4009
    /* |x| in [0,22] */
Packit 6c4009
	if (ix < 0x41b00000) {
Packit 6c4009
	    /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
Packit 6c4009
		if(ix<0x3eb17218) {
Packit 6c4009
		    if (ix<0x24000000) return one;	/* cosh(tiny) = 1 */
Packit 6c4009
		    t = __expm1f(fabsf(x));
Packit 6c4009
		    w = one+t;
Packit 6c4009
		    return one+(t*t)/(w+w);
Packit 6c4009
		}
Packit 6c4009
Packit 6c4009
	    /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
Packit 6c4009
		t = __ieee754_expf(fabsf(x));
Packit 6c4009
		return half*t+half/t;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
    /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
Packit 6c4009
	if (ix < 0x42b17180)  return half*__ieee754_expf(fabsf(x));
Packit 6c4009
Packit 6c4009
    /* |x| in [log(maxdouble), overflowthresold] */
Packit 6c4009
	if (ix<=0x42b2d4fc) {
Packit 6c4009
	    w = __ieee754_expf(half*fabsf(x));
Packit 6c4009
	    t = half*w;
Packit 6c4009
	    return t*w;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
    /* x is INF or NaN */
Packit 6c4009
	if(ix>=0x7f800000) return x*x;
Packit 6c4009
Packit 6c4009
    /* |x| > overflowthresold, cosh(x) overflow */
Packit 6c4009
	return math_narrow_eval (huge*huge);
Packit 6c4009
}
Packit 6c4009
strong_alias (__ieee754_coshf, __coshf_finite)