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