e_coshf.c revision 176451
1168515Sgshapiro/* e_coshf.c -- float version of e_cosh.c. 2168515Sgshapiro * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3168515Sgshapiro */ 4132943Sgshapiro 5266692Sgshapiro/* 6132943Sgshapiro * ==================================================== 7168515Sgshapiro * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 890792Sgshapiro * 9168515Sgshapiro * Developed at SunPro, a Sun Microsystems, Inc. business. 1090792Sgshapiro * Permission to use, copy, modify, and distribute this 11168515Sgshapiro * software is freely granted, provided that this notice 12168515Sgshapiro * is preserved. 1390792Sgshapiro * ==================================================== 1490792Sgshapiro */ 1590792Sgshapiro 16168515Sgshapiro#include <sys/cdefs.h> 1790792Sgshapiro__FBSDID("$FreeBSD: head/lib/msun/src/e_coshf.c 176451 2008-02-22 02:30:36Z das $"); 18168515Sgshapiro 1990792Sgshapiro#include "math.h" 2090792Sgshapiro#include "math_private.h" 21168515Sgshapiro 22168515Sgshapirostatic const float one = 1.0, half=0.5, huge = 1.0e30; 23168515Sgshapiro 24168515Sgshapirofloat 25168515Sgshapiro__ieee754_coshf(float x) 26168515Sgshapiro{ 27168515Sgshapiro float t,w; 28168515Sgshapiro int32_t ix; 29168515Sgshapiro 30168515Sgshapiro GET_FLOAT_WORD(ix,x); 31168515Sgshapiro ix &= 0x7fffffff; 3290792Sgshapiro 3390792Sgshapiro /* x is INF or NaN */ 34168515Sgshapiro if(ix>=0x7f800000) return x*x; 35168515Sgshapiro 3690792Sgshapiro /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ 37168515Sgshapiro if(ix<0x3eb17218) { 38168515Sgshapiro t = expm1f(fabsf(x)); 3990792Sgshapiro w = one+t; 40168515Sgshapiro if (ix<0x39800000) return one; /* cosh(tiny) = 1 */ 4190792Sgshapiro return one+(t*t)/(w+w); 42168515Sgshapiro } 43168515Sgshapiro 44261363Sgshapiro /* |x| in [0.5*ln2,9], return (exp(|x|)+1/exp(|x|))/2; */ 4590792Sgshapiro if (ix < 0x41100000) { 46168515Sgshapiro t = __ieee754_expf(fabsf(x)); 4790792Sgshapiro return half*t+half/t; 48112810Sgshapiro } 49168515Sgshapiro 50168515Sgshapiro /* |x| in [9, log(maxfloat)] return half*exp(|x|) */ 51168515Sgshapiro if (ix < 0x42b17217) return half*__ieee754_expf(fabsf(x)); 52 53 /* |x| in [log(maxfloat), overflowthresold] */ 54 if (ix<=0x42b2d4fc) { 55 w = __ieee754_expf(half*fabsf(x)); 56 t = half*w; 57 return t*w; 58 } 59 60 /* |x| > overflowthresold, cosh(x) overflow */ 61 return huge*huge; 62} 63