acosh.c revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * CDDL HEADER START
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * The contents of this file are subject to the terms of the
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Common Development and Distribution License (the "License").
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * You may not use this file except in compliance with the License.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * or http://www.opensolaris.org/os/licensing.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * See the License for the specific language governing permissions
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * and limitations under the License.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * When distributing Covered Code, include this CDDL HEADER in each
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * If applicable, add the following below this CDDL HEADER, with the
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * fields enclosed by brackets "[]" replaced with your own identifying
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * information: Portions Copyright [yyyy] [name of copyright owner]
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * CDDL HEADER END
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Use is subject to license terms.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg#pragma weak __acosh = acosh
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/* INDENT OFF */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(x)
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Method :
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Based on
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(x) = log [ x + sqrt(x*x-1) ]
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * we have
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(x) := log(x)+ln2, if x is large; else
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x > 2; else
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t = x-1.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Special cases:
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(x) is NaN with signal if x < 1.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * acosh(NaN) is NaN without signal.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/* INDENT ON */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg#include "libm_protos.h" /* _SVID_libm_error */
#include "libm_macros.h"
#include <math.h>
static const double
one = 1.0,
ln2 = 6.93147180559945286227e-01; /* 3FE62E42, FEFA39EF */
double
acosh(double x) {
double t;
int hx;
hx = ((int *) &x)[HIWORD];
if (hx < 0x3ff00000) { /* x < 1 */
if (isnan(x))
#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
return (hx >= 0xfff80000 ? x : (x - x) / (x - x));
/* assumes sparc-like QNaN */
#else
return (x - x) / (x - x);
#endif
else
return (_SVID_libm_err(x, x, 29));
} else if (hx >= 0x41b00000) {
/* x > 2**28 */
if (hx >= 0x7ff00000) { /* x is inf of NaN */
#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
return (hx >= 0x7ff80000 ? x : x + x);
/* assumes sparc-like QNaN */
#else
return (x + x);
#endif
} else /* acosh(huge)=log(2x) */
return (log(x) + ln2);
} else if (((hx - 0x3ff00000) | ((int *) &x)[LOWORD]) == 0) {
return (0.0); /* acosh(1) = 0 */
} else if (hx > 0x40000000) {
/* 2**28 > x > 2 */
t = x * x;
return (log(2.0 * x - one / (x + sqrt(t - one))));
} else {
/* 1 < x < 2 */
t = x - one;
return (log1p(t + sqrt(2.0 * t + t * t)));
}
}