Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libm / common_source / sinh.c
1 /*
2  * Copyright (c) 1985, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)sinh.c   8.1 (Berkeley) 6/4/93
34  */
35
36 /* SINH(X)
37  * RETURN THE HYPERBOLIC SINE OF X
38  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
39  * CODED IN C BY K.C. NG, 1/8/85;
40  * REVISED BY K.C. NG on 2/8/85, 3/7/85, 3/24/85, 4/16/85.
41  *
42  * Required system supported functions :
43  *      copysign(x,y)
44  *      scalb(x,N)
45  *
46  * Required kernel functions:
47  *      expm1(x)        ...return exp(x)-1
48  *
49  * Method :
50  *      1. reduce x to non-negative by sinh(-x) = - sinh(x).
51  *      2.
52  *
53  *                                            expm1(x) + expm1(x)/(expm1(x)+1)
54  *          0 <= x <= lnovfl     : sinh(x) := --------------------------------
55  *                                                            2
56  *     lnovfl <= x <= lnovfl+ln2 : sinh(x) := expm1(x)/2 (avoid overflow)
57  * lnovfl+ln2 <  x <  INF        :  overflow to INF
58  *
59  *
60  * Special cases:
61  *      sinh(x) is x if x is +INF, -INF, or NaN.
62  *      only sinh(0)=0 is exact for finite argument.
63  *
64  * Accuracy:
65  *      sinh(x) returns the exact hyperbolic sine of x nearly rounded. In
66  *      a test run with 1,024,000 random arguments on a VAX, the maximum
67  *      observed error was 1.93 ulps (units in the last place).
68  *
69  * Constants:
70  * The hexadecimal values are the intended ones for the following constants.
71  * The decimal values may be used, provided that the compiler will convert
72  * from decimal to binary accurately enough to produce the hexadecimal values
73  * shown.
74  */
75
76 #include "mathimpl.h"
77
78 vc(mln2hi, 8.8029691931113054792E1   ,0f33,43b0,2bdb,c7e2,   7, .B00F33C7E22BDB)
79 vc(mln2lo,-4.9650192275318476525E-16 ,1b60,a70f,582a,279e, -50,-.8F1B60279E582A)
80 vc(lnovfl, 8.8029691931113053016E1   ,0f33,43b0,2bda,c7e2,   7, .B00F33C7E22BDA)
81
82 ic(mln2hi, 7.0978271289338397310E2,    10, 1.62E42FEFA39EF)
83 ic(mln2lo, 2.3747039373786107478E-14, -45, 1.ABC9E3B39803F)
84 ic(lnovfl, 7.0978271289338397310E2,     9, 1.62E42FEFA39EF)
85
86 #ifdef vccast
87 #define mln2hi  vccast(mln2hi)
88 #define mln2lo  vccast(mln2lo)
89 #define lnovfl  vccast(lnovfl)
90 #endif
91
92 #if defined(vax)||defined(tahoe)
93 static max = 126                      ;
94 #else   /* defined(vax)||defined(tahoe) */
95 static max = 1023                     ;
96 #endif  /* defined(vax)||defined(tahoe) */
97
98
99 double sinh(x)
100 double x;
101 {
102         static const double  one=1.0, half=1.0/2.0 ;
103         double t, sign;
104 #if !defined(vax)&&!defined(tahoe)
105         if(x!=x) return(x);     /* x is NaN */
106 #endif  /* !defined(vax)&&!defined(tahoe) */
107         sign=copysign(one,x);
108         x=copysign(x,one);
109         if(x<lnovfl)
110             {t=expm1(x); return(copysign((t+t/(one+t))*half,sign));}
111
112         else if(x <= lnovfl+0.7)
113                 /* subtract x by ln(2^(max+1)) and return 2^max*exp(x)
114                         to avoid unnecessary overflow */
115             return(copysign(scalb(one+expm1((x-mln2hi)-mln2lo),max),sign));
116
117         else  /* sinh(+-INF) = +-INF, sinh(+-big no.) overflow to +-INF */
118             return( expm1(x)*sign );
119 }