|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1985 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: * ! 19: * All recipients should regard themselves as participants in an ongoing ! 20: * research project and hence should feel obligated to report their ! 21: * experiences (good or bad) with these elementary function codes, using ! 22: * the sendbug(8) program, to the authors. ! 23: */ ! 24: ! 25: #ifndef lint ! 26: static char sccsid[] = "@(#)sinh.c 5.5 (Berkeley) 6/1/90"; ! 27: #endif /* not lint */ ! 28: ! 29: /* SINH(X) ! 30: * RETURN THE HYPERBOLIC SINE OF X ! 31: * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) ! 32: * CODED IN C BY K.C. NG, 1/8/85; ! 33: * REVISED BY K.C. NG on 2/8/85, 3/7/85, 3/24/85, 4/16/85. ! 34: * ! 35: * Required system supported functions : ! 36: * copysign(x,y) ! 37: * scalb(x,N) ! 38: * ! 39: * Required kernel functions: ! 40: * expm1(x) ...return exp(x)-1 ! 41: * ! 42: * Method : ! 43: * 1. reduce x to non-negative by sinh(-x) = - sinh(x). ! 44: * 2. ! 45: * ! 46: * expm1(x) + expm1(x)/(expm1(x)+1) ! 47: * 0 <= x <= lnovfl : sinh(x) := -------------------------------- ! 48: * 2 ! 49: * lnovfl <= x <= lnovfl+ln2 : sinh(x) := expm1(x)/2 (avoid overflow) ! 50: * lnovfl+ln2 < x < INF : overflow to INF ! 51: * ! 52: * ! 53: * Special cases: ! 54: * sinh(x) is x if x is +INF, -INF, or NaN. ! 55: * only sinh(0)=0 is exact for finite argument. ! 56: * ! 57: * Accuracy: ! 58: * sinh(x) returns the exact hyperbolic sine of x nearly rounded. In ! 59: * a test run with 1,024,000 random arguments on a VAX, the maximum ! 60: * observed error was 1.93 ulps (units in the last place). ! 61: * ! 62: * Constants: ! 63: * The hexadecimal values are the intended ones for the following constants. ! 64: * The decimal values may be used, provided that the compiler will convert ! 65: * from decimal to binary accurately enough to produce the hexadecimal values ! 66: * shown. ! 67: */ ! 68: ! 69: #include "mathimpl.h" ! 70: ! 71: vc(mln2hi, 8.8029691931113054792E1 ,0f33,43b0,2bdb,c7e2, 7, .B00F33C7E22BDB) ! 72: vc(mln2lo,-4.9650192275318476525E-16 ,1b60,a70f,582a,279e, -50,-.8F1B60279E582A) ! 73: vc(lnovfl, 8.8029691931113053016E1 ,0f33,43b0,2bda,c7e2, 7, .B00F33C7E22BDA) ! 74: ! 75: ic(mln2hi, 7.0978271289338397310E2, 10, 1.62E42FEFA39EF) ! 76: ic(mln2lo, 2.3747039373786107478E-14, -45, 1.ABC9E3B39803F) ! 77: ic(lnovfl, 7.0978271289338397310E2, 9, 1.62E42FEFA39EF) ! 78: ! 79: #ifdef vccast ! 80: #define mln2hi vccast(mln2hi) ! 81: #define mln2lo vccast(mln2lo) ! 82: #define lnovfl vccast(lnovfl) ! 83: #endif ! 84: ! 85: #if defined(vax)||defined(tahoe) ! 86: static max = 126 ; ! 87: #else /* defined(vax)||defined(tahoe) */ ! 88: static max = 1023 ; ! 89: #endif /* defined(vax)||defined(tahoe) */ ! 90: ! 91: ! 92: double sinh(x) ! 93: double x; ! 94: { ! 95: static const double one=1.0, half=1.0/2.0 ; ! 96: double t, sign; ! 97: #if !defined(vax)&&!defined(tahoe) ! 98: if(x!=x) return(x); /* x is NaN */ ! 99: #endif /* !defined(vax)&&!defined(tahoe) */ ! 100: sign=copysign(one,x); ! 101: x=copysign(x,one); ! 102: if(x<lnovfl) ! 103: {t=expm1(x); return(copysign((t+t/(one+t))*half,sign));} ! 104: ! 105: else if(x <= lnovfl+0.7) ! 106: /* subtract x by ln(2^(max+1)) and return 2^max*exp(x) ! 107: to avoid unnecessary overflow */ ! 108: return(copysign(scalb(one+expm1((x-mln2hi)-mln2lo),max),sign)); ! 109: ! 110: else /* sinh(+-INF) = +-INF, sinh(+-big no.) overflow to +-INF */ ! 111: return( expm1(x)*sign ); ! 112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.