hjl / source-git / glibc

Forked from source-git/glibc 4 years ago
Clone

Blame sysdeps/ieee754/ldbl-96/e_coshl.c

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: e_cosh.c,v 1.7 1995/05/10 20:44:58 jtc Exp $";
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* __ieee754_coshl(x)
Packit 6c4009
 * Method :
Packit 6c4009
 * mathematically coshl(x) if defined to be (exp(x)+exp(-x))/2
Packit 6c4009
 *	1. Replace x by |x| (coshl(x) = coshl(-x)).
Packit 6c4009
 *	2.
Packit 6c4009
 *							[ exp(x) - 1 ]^2
Packit 6c4009
 *	    0        <= x <= ln2/2  :  coshl(x) := 1 + -------------------
Packit 6c4009
 *							   2*exp(x)
Packit 6c4009
 *
Packit 6c4009
 *						   exp(x) +  1/exp(x)
Packit 6c4009
 *	    ln2/2    <= x <= 22     :  coshl(x) := -------------------
Packit 6c4009
 *							   2
Packit 6c4009
 *	    22       <= x <= lnovft :  coshl(x) := expl(x)/2
Packit 6c4009
 *	    lnovft   <= x <= ln2ovft:  coshl(x) := expl(x/2)/2 * expl(x/2)
Packit 6c4009
 *	    ln2ovft  <  x	    :  coshl(x) := huge*huge (overflow)
Packit 6c4009
 *
Packit 6c4009
 * Special cases:
Packit 6c4009
 *	coshl(x) is |x| if x is +INF, -INF, or NaN.
Packit 6c4009
 *	only coshl(0)=1 is exact for finite x.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
static const long double one = 1.0, half=0.5, huge = 1.0e4900L;
Packit 6c4009
Packit 6c4009
long double
Packit 6c4009
__ieee754_coshl (long double x)
Packit 6c4009
{
Packit 6c4009
	long double t,w;
Packit 6c4009
	int32_t ex;
Packit 6c4009
	uint32_t mx,lx;
Packit 6c4009
Packit 6c4009
    /* High word of |x|. */
Packit 6c4009
	GET_LDOUBLE_WORDS(ex,mx,lx,x);
Packit 6c4009
	ex &= 0x7fff;
Packit 6c4009
Packit 6c4009
    /* |x| in [0,22] */
Packit 6c4009
	if (ex < 0x4003 || (ex == 0x4003 && mx < 0xb0000000u)) {
Packit 6c4009
	    /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */
Packit 6c4009
		if(ex < 0x3ffd || (ex == 0x3ffd && mx < 0xb17217f7u)) {
Packit 6c4009
		    if (ex<0x3fbc) return one;	/* cosh(tiny) = 1 */
Packit 6c4009
		    t = __expm1l(fabsl(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_expl(fabsl(x));
Packit 6c4009
		return half*t+half/t;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
    /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */
Packit 6c4009
	if (ex < 0x400c || (ex == 0x400c && mx < 0xb1700000u))
Packit 6c4009
		return half*__ieee754_expl(fabsl(x));
Packit 6c4009
Packit 6c4009
    /* |x| in [log(maxdouble), log(2*maxdouble)) */
Packit 6c4009
	if (ex == 0x400c && (mx < 0xb174ddc0u
Packit 6c4009
			     || (mx == 0xb174ddc0u && lx < 0x31aec0ebu)))
Packit 6c4009
	{
Packit 6c4009
	    w = __ieee754_expl(half*fabsl(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(ex==0x7fff) return x*x;
Packit 6c4009
Packit 6c4009
    /* |x| >= log(2*maxdouble), cosh(x) overflow */
Packit 6c4009
	return huge*huge;
Packit 6c4009
}
Packit 6c4009
strong_alias (__ieee754_coshl, __coshl_finite)