134126Sbostic /* 224606Szliu * Copyright (c) 1985 Regents of the University of California. 334126Sbostic * All rights reserved. 434126Sbostic * 534126Sbostic * Redistribution and use in source and binary forms are permitted 634931Sbostic * provided that the above copyright notice and this paragraph are 734931Sbostic * duplicated in all such forms and that any documentation, 834931Sbostic * advertising materials, and other materials related to such 934931Sbostic * distribution and use acknowledge that the software was developed 1034931Sbostic * by the University of California, Berkeley. The name of the 1134931Sbostic * University may not be used to endorse or promote products derived 1234931Sbostic * from this software without specific prior written permission. 1334931Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434931Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534931Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634126Sbostic * 1734126Sbostic * All recipients should regard themselves as participants in an ongoing 1834126Sbostic * research project and hence should feel obligated to report their 1934126Sbostic * experiences (good or bad) with these elementary function codes, using 2034126Sbostic * the sendbug(8) program, to the authors. 2124606Szliu */ 2224606Szliu 2324606Szliu #ifndef lint 24*35679Sbostic static char sccsid[] = "@(#)sinh.c 5.4 (Berkeley) 09/22/88"; 2534126Sbostic #endif /* not lint */ 2624606Szliu 2724606Szliu /* SINH(X) 2824606Szliu * RETURN THE HYPERBOLIC SINE OF X 2924606Szliu * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 3024606Szliu * CODED IN C BY K.C. NG, 1/8/85; 3124606Szliu * REVISED BY K.C. NG on 2/8/85, 3/7/85, 3/24/85, 4/16/85. 3224606Szliu * 3324606Szliu * Required system supported functions : 3424606Szliu * copysign(x,y) 3524606Szliu * scalb(x,N) 3624606Szliu * 3724606Szliu * Required kernel functions: 3824606Szliu * expm1(x) ...return exp(x)-1 3924606Szliu * 4024606Szliu * Method : 4124606Szliu * 1. reduce x to non-negative by sinh(-x) = - sinh(x). 4224606Szliu * 2. 4324606Szliu * 4424606Szliu * expm1(x) + expm1(x)/(expm1(x)+1) 4524606Szliu * 0 <= x <= lnovfl : sinh(x) := -------------------------------- 4624606Szliu * 2 4724606Szliu * lnovfl <= x <= lnovfl+ln2 : sinh(x) := expm1(x)/2 (avoid overflow) 4824606Szliu * lnovfl+ln2 < x < INF : overflow to INF 4924606Szliu * 5024606Szliu * 5124606Szliu * Special cases: 5224606Szliu * sinh(x) is x if x is +INF, -INF, or NaN. 5324606Szliu * only sinh(0)=0 is exact for finite argument. 5424606Szliu * 5524606Szliu * Accuracy: 5624606Szliu * sinh(x) returns the exact hyperbolic sine of x nearly rounded. In 5724606Szliu * a test run with 1,024,000 random arguments on a VAX, the maximum 5824606Szliu * observed error was 1.93 ulps (units in the last place). 5924606Szliu * 6024606Szliu * Constants: 6124606Szliu * The hexadecimal values are the intended ones for the following constants. 6224606Szliu * The decimal values may be used, provided that the compiler will convert 6324606Szliu * from decimal to binary accurately enough to produce the hexadecimal values 6424606Szliu * shown. 6524606Szliu */ 6624606Szliu 67*35679Sbostic #include "mathimpl.h" 68*35679Sbostic 69*35679Sbostic vc(mln2hi, 8.8029691931113054792E1 ,0f33,43b0,2bdb,c7e2, 7, .B00F33C7E22BDB) 70*35679Sbostic vc(mln2lo,-4.9650192275318476525E-16 ,1b60,a70f,582a,279e, -50,-.8F1B60279E582A) 71*35679Sbostic vc(lnovfl, 8.8029691931113053016E1 ,0f33,43b0,2bda,c7e2, 7, .B00F33C7E22BDA) 72*35679Sbostic 73*35679Sbostic ic(mln2hi, 7.0978271289338397310E2, 10, 1.62E42FEFA39EF) 74*35679Sbostic ic(mln2lo, 2.3747039373786107478E-14, -45, 1.ABC9E3B39803F) 75*35679Sbostic ic(lnovfl, 7.0978271289338397310E2, 9, 1.62E42FEFA39EF) 76*35679Sbostic 77*35679Sbostic #ifdef vccast 78*35679Sbostic #define mln2hi vccast(mln2hi) 79*35679Sbostic #define mln2lo vccast(mln2lo) 80*35679Sbostic #define lnovfl vccast(lnovfl) 81*35679Sbostic #endif 82*35679Sbostic 8331853Szliu #if defined(vax)||defined(tahoe) 8424606Szliu static max = 126 ; 8531853Szliu #else /* defined(vax)||defined(tahoe) */ 8624606Szliu static max = 1023 ; 8731853Szliu #endif /* defined(vax)||defined(tahoe) */ 8824606Szliu 8924606Szliu 9024606Szliu double sinh(x) 9124606Szliu double x; 9224606Szliu { 93*35679Sbostic static const double one=1.0, half=1.0/2.0 ; 94*35679Sbostic double t, sign; 9531853Szliu #if !defined(vax)&&!defined(tahoe) 9624606Szliu if(x!=x) return(x); /* x is NaN */ 9731853Szliu #endif /* !defined(vax)&&!defined(tahoe) */ 9824606Szliu sign=copysign(one,x); 9924606Szliu x=copysign(x,one); 10024606Szliu if(x<lnovfl) 10124606Szliu {t=expm1(x); return(copysign((t+t/(one+t))*half,sign));} 10224606Szliu 10324606Szliu else if(x <= lnovfl+0.7) 10424606Szliu /* subtract x by ln(2^(max+1)) and return 2^max*exp(x) 10524606Szliu to avoid unnecessary overflow */ 10624606Szliu return(copysign(scalb(one+expm1((x-mln2hi)-mln2lo),max),sign)); 10724606Szliu 10824606Szliu else /* sinh(+-INF) = +-INF, sinh(+-big no.) overflow to +-INF */ 10924606Szliu return( expm1(x)*sign ); 11024606Szliu } 111