Back to index

glibc  2.9
e_coshf.c
Go to the documentation of this file.
00001 /* e_coshf.c -- float version of e_cosh.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: e_coshf.c,v 1.6 1996/04/08 15:43:41 phil Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include "math_private.h"
00022 
00023 #ifdef __STDC__
00024 static const float huge = 1.0e30;
00025 static const float one = 1.0, half=0.5;
00026 #else
00027 static float one = 1.0, half=0.5, huge = 1.0e30;
00028 #endif
00029 
00030 #ifdef __STDC__
00031        float __ieee754_coshf(float x)
00032 #else
00033        float __ieee754_coshf(x)
00034        float x;
00035 #endif
00036 {
00037        float t,w;
00038        int32_t ix;
00039 
00040        GET_FLOAT_WORD(ix,x);
00041        ix &= 0x7fffffff;
00042 
00043     /* x is INF or NaN */
00044        if(ix>=0x7f800000) return x*x;
00045 
00046     /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
00047        if(ix<0x3eb17218) {
00048            t = __expm1f(fabsf(x));
00049            w = one+t;
00050            if (ix<0x24000000) return w;   /* cosh(tiny) = 1 */
00051            return one+(t*t)/(w+w);
00052        }
00053 
00054     /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
00055        if (ix < 0x41b00000) {
00056               t = __ieee754_expf(fabsf(x));
00057               return half*t+half/t;
00058        }
00059 
00060     /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
00061        if (ix < 0x42b17180)  return half*__ieee754_expf(fabsf(x));
00062 
00063     /* |x| in [log(maxdouble), overflowthresold] */
00064        if (ix<=0x42b2d4fc) {
00065            w = __ieee754_expf(half*fabsf(x));
00066            t = half*w;
00067            return t*w;
00068        }
00069 
00070     /* |x| > overflowthresold, cosh(x) overflow */
00071        return huge*huge;
00072 }