mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Ported cosf(), coshf(), sinf(), sinhf(), tanf(), tanhf()
and hypotf() for C99. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14964 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_coshf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_coshf.c,v 1.2 2005-05-30 08:10:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,46 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float one = 1.0, half=0.5, huge = 1.0e30;
|
||||
|
||||
float
|
||||
coshf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float t,w;
|
||||
LONG ix;
|
||||
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
/* x is INF or NaN */
|
||||
if(ix>=0x7f800000) return x*x;
|
||||
|
||||
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
|
||||
if(ix<0x3eb17218) {
|
||||
t = expm1f(fabsf(x));
|
||||
w = one+t;
|
||||
if (ix<0x24000000) return w; /* cosh(tiny) = 1 */
|
||||
return one+(t*t)/(w+w);
|
||||
}
|
||||
|
||||
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
|
||||
if (ix < 0x41b00000) {
|
||||
t = expf(fabsf(x));
|
||||
return half*t+half/t;
|
||||
}
|
||||
|
||||
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
|
||||
if (ix < 0x42b17180) return half*expf(fabsf(x));
|
||||
|
||||
/* |x| in [log(maxdouble), overflowthresold] */
|
||||
if (ix<=0x42b2d4fc) {
|
||||
w = expf(half*fabsf(x));
|
||||
t = half*w;
|
||||
return t*w;
|
||||
}
|
||||
|
||||
/* |x| > overflowthresold, cosh(x) overflow */
|
||||
return huge*huge;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user