da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "FEATURE/uwin"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !_UWIN || _lib_acosh
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvoid _STUB_acosh(){}
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[] = "@(#)acosh.c 8.1 (Berkeley) 6/4/93";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* not lint */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* ACOSH(X)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * RETURN THE INVERSE HYPERBOLIC COSINE 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/6/85, 3/24/85, 4/16/85, 8/17/85.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Required system supported functions :
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * sqrt(x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Required kernel function:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * log1p(x) ...return log(1+x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Method :
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Based on
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * acosh(x) = log [ x + sqrt(x*x-1) ]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * we have
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * acosh(x) := log1p(x)+ln2, if (x > 1.0E20); else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * acosh(x) := log1p( sqrt(x-1) * (sqrt(x-1) + sqrt(x+1)) ) .
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * These formulae avoid the over/underflow complication.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Special cases:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * acosh(x) is NaN with signal if x<1.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * acosh(NaN) is NaN without signal.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Accuracy:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * acosh(x) returns the exact inverse hyperbolic cosine of x nearly
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * rounded. In a test run with 512,000 random arguments on a VAX, the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * maximum observed error was 3.30 ulps (units of the last place) at
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * x=1.0070493753568216 .
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
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 acosh(x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindouble x;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin double t,big=1.E20; /* big+1==big */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(vax)&&!defined(tahoe)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(x!=x) return(x); /* x is NaN */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* !defined(vax)&&!defined(tahoe) */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* return log1p(x) + log(2) if x is large */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(x>big) {t=log1p(x)+ln2lo; return(t+ln2hi);}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin t=sqrt(x-1.0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(log1p(t*(t+sqrt(x+1.0))));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif