11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* @(#)s_asinh.c 5.1 93/09/24 */
21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ====================================================
41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Developed at SunPro, a Sun Microsystems, Inc. business.
71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Permission to use, copy, modify, and distribute this
81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * software is freely granted, provided that this notice
91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * is preserved.
101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ====================================================
111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
13a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#include <sys/cdefs.h>
14a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes__FBSDID("$FreeBSD$");
151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* asinh(x)
171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Method :
181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *	Based on
191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *		asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *	we have
211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *	asinh(x) := x  if  1+x*x=1,
221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *		 := sign(x)*(log(x)+ln2)) for large |x|, else
231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *		 := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *		 := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2778419467a2f88744ae2445fca5eb442877ebb1b0Elliott Hughes#include <float.h>
2878419467a2f88744ae2445fca5eb442877ebb1b0Elliott Hughes
291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "math.h"
301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "math_private.h"
311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic const double
331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectone =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectln2 =  6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecthuge=  1.00000000000000000000e+300;
361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectdouble
381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectasinh(double x)
391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{
401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	double t,w;
411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	int32_t hx,ix;
421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	GET_HIGH_WORD(hx,x);
431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	ix = hx&0x7fffffff;
441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	if(ix>=0x7ff00000) return x+x;	/* x is inf or NaN */
451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	if(ix< 0x3e300000) {	/* |x|<2**-28 */
461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    if(huge+x>one) return x;	/* return x inexact except 0 */
471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	}
481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	if(ix>0x41b00000) {	/* |x| > 2**28 */
491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    w = __ieee754_log(fabs(x))+ln2;
501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	} else if (ix>0x40000000) {	/* 2**28 > |x| > 2.0 */
511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    t = fabs(x);
521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	} else {		/* 2.0 > |x| > 2**-28 */
541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    t = x*x;
551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	}
571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	if(hx>0) return w; else return -w;
581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
5978419467a2f88744ae2445fca5eb442877ebb1b0Elliott Hughes
6078419467a2f88744ae2445fca5eb442877ebb1b0Elliott Hughes#if LDBL_MANT_DIG == 53
6178419467a2f88744ae2445fca5eb442877ebb1b0Elliott Hughes__weak_reference(asinh, asinhl);
6278419467a2f88744ae2445fca5eb442877ebb1b0Elliott Hughes#endif
63