[444] | 1 | |
---|
| 2 | /* @(#)w_cosh.c 5.1 93/09/24 */ |
---|
| 3 | /* |
---|
| 4 | * ==================================================== |
---|
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
| 6 | * |
---|
| 7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
| 8 | * Permission to use, copy, modify, and distribute this |
---|
| 9 | * software is freely granted, provided that this notice |
---|
| 10 | * is preserved. |
---|
| 11 | * ==================================================== |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | |
---|
| 16 | FUNCTION |
---|
| 17 | <<cosh>>, <<coshf>>---hyperbolic cosine |
---|
| 18 | |
---|
| 19 | SYNOPSIS |
---|
| 20 | #include <math.h> |
---|
| 21 | double cosh(double <[x]>); |
---|
| 22 | float coshf(float <[x]>); |
---|
| 23 | |
---|
| 24 | DESCRIPTION |
---|
| 25 | |
---|
| 26 | <<cosh>> computes the hyperbolic cosine of the argument <[x]>. |
---|
| 27 | <<cosh(<[x]>)>> is defined as |
---|
| 28 | @ifnottex |
---|
| 29 | . (exp(x) + exp(-x))/2 |
---|
| 30 | @end ifnottex |
---|
| 31 | @tex |
---|
| 32 | $${(e^x + e^{-x})} \over 2$$ |
---|
| 33 | @end tex |
---|
| 34 | |
---|
| 35 | Angles are specified in radians. |
---|
| 36 | |
---|
| 37 | <<coshf>> is identical, save that it takes and returns <<float>>. |
---|
| 38 | |
---|
| 39 | RETURNS |
---|
| 40 | The computed value is returned. When the correct value would create |
---|
| 41 | an overflow, <<cosh>> returns the value <<HUGE_VAL>> with the |
---|
| 42 | appropriate sign, and the global value <<errno>> is set to <<ERANGE>>. |
---|
| 43 | |
---|
| 44 | You can modify error handling for these functions using the |
---|
| 45 | function <<matherr>>. |
---|
| 46 | |
---|
| 47 | PORTABILITY |
---|
| 48 | <<cosh>> is ANSI. |
---|
| 49 | <<coshf>> is an extension. |
---|
| 50 | |
---|
| 51 | QUICKREF |
---|
| 52 | cosh ansi pure |
---|
| 53 | coshf - pure |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * wrapper cosh(x) |
---|
| 58 | */ |
---|
| 59 | |
---|
| 60 | #include "fdlibm.h" |
---|
| 61 | #include <errno.h> |
---|
| 62 | |
---|
| 63 | #ifndef _DOUBLE_IS_32BITS |
---|
| 64 | |
---|
| 65 | #ifdef __STDC__ |
---|
| 66 | double cosh(double x) /* wrapper cosh */ |
---|
| 67 | #else |
---|
| 68 | double cosh(x) /* wrapper cosh */ |
---|
| 69 | double x; |
---|
| 70 | #endif |
---|
| 71 | { |
---|
| 72 | #ifdef _IEEE_LIBM |
---|
| 73 | return __ieee754_cosh(x); |
---|
| 74 | #else |
---|
| 75 | double z; |
---|
| 76 | struct exception exc; |
---|
| 77 | z = __ieee754_cosh(x); |
---|
| 78 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; |
---|
| 79 | if(fabs(x)>7.10475860073943863426e+02) { |
---|
| 80 | /* cosh(finite) overflow */ |
---|
| 81 | #ifndef HUGE_VAL |
---|
| 82 | #define HUGE_VAL inf |
---|
| 83 | double inf = 0.0; |
---|
| 84 | |
---|
| 85 | SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ |
---|
| 86 | #endif |
---|
| 87 | exc.type = OVERFLOW; |
---|
| 88 | exc.name = "cosh"; |
---|
| 89 | exc.err = 0; |
---|
| 90 | exc.arg1 = exc.arg2 = x; |
---|
| 91 | if (_LIB_VERSION == _SVID_) |
---|
| 92 | exc.retval = HUGE; |
---|
| 93 | else |
---|
| 94 | exc.retval = HUGE_VAL; |
---|
| 95 | if (_LIB_VERSION == _POSIX_) |
---|
| 96 | errno = ERANGE; |
---|
| 97 | else if (!matherr(&exc)) { |
---|
| 98 | errno = ERANGE; |
---|
| 99 | } |
---|
| 100 | if (exc.err != 0) |
---|
| 101 | errno = exc.err; |
---|
| 102 | return exc.retval; |
---|
| 103 | } else |
---|
| 104 | return z; |
---|
| 105 | #endif |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|