asinh.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "FEATURE/uwin"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !_UWIN || _lib_asinh
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvoid _STUB_asinh(){}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright (c) 1985, 1993
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * The Regents of the University of California. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Redistribution and use in source and binary forms, with or without
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * modification, are permitted provided that the following conditions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * are met:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 1. Redistributions of source code must retain the above copyright
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * notice, this list of conditions and the following disclaimer.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 2. Redistributions in binary form must reproduce the above copyright
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * notice, this list of conditions and the following disclaimer in the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * documentation and/or other materials provided with the distribution.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 3. Neither the name of the University nor the names of its contributors
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * may be used to endorse or promote products derived from this software
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * without specific prior written permission.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * SUCH DAMAGE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef lint
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char sccsid[] = "@(#)asinh.c 8.1 (Berkeley) 6/4/93";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* not lint */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* ASINH(X)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * RETURN THE INVERSE HYPERBOLIC SINE OF X
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CODED IN C BY K.C. NG, 2/16/85;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Required system supported functions :
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * copysign(x,y)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * sqrt(x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Required kernel function:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * log1p(x) ...return log(1+x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Method :
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Based on
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * we have
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * asinh(x) := x if 1+x*x=1,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * := sign(x)*(log1p(x)+ln2)) if sqrt(1+x*x)=x, else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Accuracy:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * In a test run with 52,000 random arguments on a VAX, the maximum
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * observed error was 1.58 ulps (units in the last place).
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Constants:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * The hexadecimal values are the intended ones for the following constants.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * The decimal values may be used, provided that the compiler will convert
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * from decimal to binary accurately enough to produce the hexadecimal values
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * shown.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "mathimpl.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvc(ln2hi, 6.9314718055829871446E-1 ,7217,4031,0000,f7d0, 0, .B17217F7D00000)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinic(ln2hi, 6.9314718036912381649E-1, -1, 1.62E42FEE00000)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinic(ln2lo, 1.9082149292705877000E-10, -33, 1.A39EF35793C76)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef vccast
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define ln2hi vccast(ln2hi)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define ln2lo vccast(ln2lo)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern double asinh(x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindouble x;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin double t,s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const static double small=1.0E-10, /* fl(1+small*small) == 1 */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin big =1.0E20, /* fl(1+big) == big */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin one =1.0 ;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(vax)&&!defined(tahoe)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(x!=x) return(x); /* x is NaN */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* !defined(vax)&&!defined(tahoe) */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if((t=copysign(x,one))>small)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(t<big) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else /* if |x| > big */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else /* if |x| < small */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(x);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif