|
|
/* @(#)w_cosh.c 5.1 93/09/24 */
|
/* @(#)w_cosh.c 5.1 93/09/24 */
|
/*
|
/*
|
* ====================================================
|
* ====================================================
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
*
|
*
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
* Permission to use, copy, modify, and distribute this
|
* Permission to use, copy, modify, and distribute this
|
* software is freely granted, provided that this notice
|
* software is freely granted, provided that this notice
|
* is preserved.
|
* is preserved.
|
* ====================================================
|
* ====================================================
|
*/
|
*/
|
|
|
/*
|
/*
|
|
|
FUNCTION
|
FUNCTION
|
<<cosh>>, <<coshf>>---hyperbolic cosine
|
<<cosh>>, <<coshf>>---hyperbolic cosine
|
|
|
ANSI_SYNOPSIS
|
ANSI_SYNOPSIS
|
#include <math.h>
|
#include <math.h>
|
double cosh(double <[x]>);
|
double cosh(double <[x]>);
|
float coshf(float <[x]>)
|
float coshf(float <[x]>)
|
|
|
TRAD_SYNOPSIS
|
TRAD_SYNOPSIS
|
#include <math.h>
|
#include <math.h>
|
double cosh(<[x]>)
|
double cosh(<[x]>)
|
double <[x]>;
|
double <[x]>;
|
|
|
float coshf(<[x]>)
|
float coshf(<[x]>)
|
float <[x]>;
|
float <[x]>;
|
|
|
DESCRIPTION
|
DESCRIPTION
|
|
|
<<cosh>> computes the hyperbolic cosine of the argument <[x]>.
|
<<cosh>> computes the hyperbolic cosine of the argument <[x]>.
|
<<cosh(<[x]>)>> is defined as
|
<<cosh(<[x]>)>> is defined as
|
@ifinfo
|
@ifinfo
|
. (exp(x) + exp(-x))/2
|
. (exp(x) + exp(-x))/2
|
@end ifinfo
|
@end ifinfo
|
@tex
|
@tex
|
$${(e^x + e^{-x})} \over 2$$
|
$${(e^x + e^{-x})} \over 2$$
|
@end tex
|
@end tex
|
|
|
Angles are specified in radians.
|
Angles are specified in radians.
|
|
|
<<coshf>> is identical, save that it takes and returns <<float>>.
|
<<coshf>> is identical, save that it takes and returns <<float>>.
|
|
|
RETURNS
|
RETURNS
|
The computed value is returned. When the correct value would create
|
The computed value is returned. When the correct value would create
|
an overflow, <<cosh>> returns the value <<HUGE_VAL>> with the
|
an overflow, <<cosh>> returns the value <<HUGE_VAL>> with the
|
appropriate sign, and the global value <<errno>> is set to <<ERANGE>>.
|
appropriate sign, and the global value <<errno>> is set to <<ERANGE>>.
|
|
|
You can modify error handling for these functions using the
|
You can modify error handling for these functions using the
|
function <<matherr>>.
|
function <<matherr>>.
|
|
|
PORTABILITY
|
PORTABILITY
|
<<cosh>> is ANSI.
|
<<cosh>> is ANSI.
|
<<coshf>> is an extension.
|
<<coshf>> is an extension.
|
|
|
QUICKREF
|
QUICKREF
|
cosh ansi pure
|
cosh ansi pure
|
coshf - pure
|
coshf - pure
|
*/
|
*/
|
|
|
/*
|
/*
|
* wrapper cosh(x)
|
* wrapper cosh(x)
|
*/
|
*/
|
|
|
#include "fdlibm.h"
|
#include "fdlibm.h"
|
#include <errno.h>
|
#include <errno.h>
|
|
|
#ifndef _DOUBLE_IS_32BITS
|
#ifndef _DOUBLE_IS_32BITS
|
|
|
#ifdef __STDC__
|
#ifdef __STDC__
|
double cosh(double x) /* wrapper cosh */
|
double cosh(double x) /* wrapper cosh */
|
#else
|
#else
|
double cosh(x) /* wrapper cosh */
|
double cosh(x) /* wrapper cosh */
|
double x;
|
double x;
|
#endif
|
#endif
|
{
|
{
|
#ifdef _IEEE_LIBM
|
#ifdef _IEEE_LIBM
|
return __ieee754_cosh(x);
|
return __ieee754_cosh(x);
|
#else
|
#else
|
double z;
|
double z;
|
struct exception exc;
|
struct exception exc;
|
z = __ieee754_cosh(x);
|
z = __ieee754_cosh(x);
|
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
|
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
|
if(fabs(x)>7.10475860073943863426e+02) {
|
if(fabs(x)>7.10475860073943863426e+02) {
|
/* cosh(finite) overflow */
|
/* cosh(finite) overflow */
|
#ifndef HUGE_VAL
|
#ifndef HUGE_VAL
|
#define HUGE_VAL inf
|
#define HUGE_VAL inf
|
double inf = 0.0;
|
double inf = 0.0;
|
|
|
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
|
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
|
#endif
|
#endif
|
exc.type = OVERFLOW;
|
exc.type = OVERFLOW;
|
exc.name = "cosh";
|
exc.name = "cosh";
|
exc.err = 0;
|
exc.err = 0;
|
exc.arg1 = exc.arg2 = x;
|
exc.arg1 = exc.arg2 = x;
|
if (_LIB_VERSION == _SVID_)
|
if (_LIB_VERSION == _SVID_)
|
exc.retval = HUGE;
|
exc.retval = HUGE;
|
else
|
else
|
exc.retval = HUGE_VAL;
|
exc.retval = HUGE_VAL;
|
if (_LIB_VERSION == _POSIX_)
|
if (_LIB_VERSION == _POSIX_)
|
errno = ERANGE;
|
errno = ERANGE;
|
else if (!matherr(&exc)) {
|
else if (!matherr(&exc)) {
|
errno = ERANGE;
|
errno = ERANGE;
|
}
|
}
|
if (exc.err != 0)
|
if (exc.err != 0)
|
errno = exc.err;
|
errno = exc.err;
|
return exc.retval;
|
return exc.retval;
|
} else
|
} else
|
return z;
|
return z;
|
#endif
|
#endif
|
}
|
}
|
|
|
#endif /* defined(_DOUBLE_IS_32BITS) */
|
#endif /* defined(_DOUBLE_IS_32BITS) */
|
|
|