| 1 | |
|---|
| 2 | /* @(#)w_sinh.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 | <<sinh>>, <<sinhf>>---hyperbolic sine |
|---|
| 18 | |
|---|
| 19 | INDEX |
|---|
| 20 | sinh |
|---|
| 21 | INDEX |
|---|
| 22 | sinhf |
|---|
| 23 | |
|---|
| 24 | SYNOPSIS |
|---|
| 25 | #include <math.h> |
|---|
| 26 | double sinh(double <[x]>); |
|---|
| 27 | float sinhf(float <[x]>); |
|---|
| 28 | |
|---|
| 29 | DESCRIPTION |
|---|
| 30 | <<sinh>> computes the hyperbolic sine of the argument <[x]>. |
|---|
| 31 | Angles are specified in radians. <<sinh>>(<[x]>) is defined as |
|---|
| 32 | @ifnottex |
|---|
| 33 | . (exp(<[x]>) - exp(-<[x]>))/2 |
|---|
| 34 | @end ifnottex |
|---|
| 35 | @tex |
|---|
| 36 | $${e^x - e^{-x}}\over 2$$ |
|---|
| 37 | @end tex |
|---|
| 38 | |
|---|
| 39 | <<sinhf>> is identical, save that it takes and returns <<float>> values. |
|---|
| 40 | |
|---|
| 41 | RETURNS |
|---|
| 42 | The hyperbolic sine of <[x]> is returned. |
|---|
| 43 | |
|---|
| 44 | When the correct result is too large to be representable (an |
|---|
| 45 | overflow), <<sinh>> returns <<HUGE_VAL>> with the |
|---|
| 46 | appropriate sign, and sets the global value <<errno>> to |
|---|
| 47 | <<ERANGE>>. |
|---|
| 48 | |
|---|
| 49 | You can modify error handling for these functions with <<matherr>>. |
|---|
| 50 | |
|---|
| 51 | PORTABILITY |
|---|
| 52 | <<sinh>> is ANSI C. |
|---|
| 53 | <<sinhf>> is an extension. |
|---|
| 54 | |
|---|
| 55 | QUICKREF |
|---|
| 56 | sinh ansi pure |
|---|
| 57 | sinhf - pure |
|---|
| 58 | */ |
|---|
| 59 | |
|---|
| 60 | /* |
|---|
| 61 | * wrapper sinh(x) |
|---|
| 62 | */ |
|---|
| 63 | |
|---|
| 64 | #include "fdlibm.h" |
|---|
| 65 | #include <errno.h> |
|---|
| 66 | |
|---|
| 67 | #ifndef _DOUBLE_IS_32BITS |
|---|
| 68 | |
|---|
| 69 | #ifdef __STDC__ |
|---|
| 70 | double sinh(double x) /* wrapper sinh */ |
|---|
| 71 | #else |
|---|
| 72 | double sinh(x) /* wrapper sinh */ |
|---|
| 73 | double x; |
|---|
| 74 | #endif |
|---|
| 75 | { |
|---|
| 76 | #ifdef _IEEE_LIBM |
|---|
| 77 | return __ieee754_sinh(x); |
|---|
| 78 | #else |
|---|
| 79 | double z; |
|---|
| 80 | struct exception exc; |
|---|
| 81 | z = __ieee754_sinh(x); |
|---|
| 82 | if(_LIB_VERSION == _IEEE_) return z; |
|---|
| 83 | if(!finite(z)&&finite(x)) { |
|---|
| 84 | /* sinh(finite) overflow */ |
|---|
| 85 | #ifndef HUGE_VAL |
|---|
| 86 | #define HUGE_VAL inf |
|---|
| 87 | double inf = 0.0; |
|---|
| 88 | |
|---|
| 89 | SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ |
|---|
| 90 | #endif |
|---|
| 91 | exc.type = OVERFLOW; |
|---|
| 92 | exc.name = "sinh"; |
|---|
| 93 | exc.err = 0; |
|---|
| 94 | exc.arg1 = exc.arg2 = x; |
|---|
| 95 | if (_LIB_VERSION == _SVID_) |
|---|
| 96 | exc.retval = ( (x>0.0) ? HUGE : -HUGE); |
|---|
| 97 | else |
|---|
| 98 | exc.retval = ( (x>0.0) ? HUGE_VAL : -HUGE_VAL); |
|---|
| 99 | if (_LIB_VERSION == _POSIX_) |
|---|
| 100 | errno = ERANGE; |
|---|
| 101 | else if (!matherr(&exc)) { |
|---|
| 102 | errno = ERANGE; |
|---|
| 103 | } |
|---|
| 104 | if (exc.err != 0) |
|---|
| 105 | errno = exc.err; |
|---|
| 106 | return exc.retval; |
|---|
| 107 | } else |
|---|
| 108 | return z; |
|---|
| 109 | #endif |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
|---|