15b2ba9d3SPiotr Jasiukajtis /*
25b2ba9d3SPiotr Jasiukajtis * CDDL HEADER START
35b2ba9d3SPiotr Jasiukajtis *
45b2ba9d3SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
55b2ba9d3SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
65b2ba9d3SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
75b2ba9d3SPiotr Jasiukajtis *
85b2ba9d3SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95b2ba9d3SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
105b2ba9d3SPiotr Jasiukajtis * See the License for the specific language governing permissions
115b2ba9d3SPiotr Jasiukajtis * and limitations under the License.
125b2ba9d3SPiotr Jasiukajtis *
135b2ba9d3SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
145b2ba9d3SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155b2ba9d3SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
165b2ba9d3SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
175b2ba9d3SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
185b2ba9d3SPiotr Jasiukajtis *
195b2ba9d3SPiotr Jasiukajtis * CDDL HEADER END
205b2ba9d3SPiotr Jasiukajtis */
215b2ba9d3SPiotr Jasiukajtis
225b2ba9d3SPiotr Jasiukajtis /*
235b2ba9d3SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
245b2ba9d3SPiotr Jasiukajtis */
255b2ba9d3SPiotr Jasiukajtis /*
265b2ba9d3SPiotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
275b2ba9d3SPiotr Jasiukajtis * Use is subject to license terms.
285b2ba9d3SPiotr Jasiukajtis */
295b2ba9d3SPiotr Jasiukajtis
30*a9d3dcd5SRichard Lowe #pragma weak __asinh = asinh
315b2ba9d3SPiotr Jasiukajtis
325b2ba9d3SPiotr Jasiukajtis /* INDENT OFF */
335b2ba9d3SPiotr Jasiukajtis /*
345b2ba9d3SPiotr Jasiukajtis * asinh(x)
355b2ba9d3SPiotr Jasiukajtis * Method :
365b2ba9d3SPiotr Jasiukajtis * Based on
375b2ba9d3SPiotr Jasiukajtis * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
385b2ba9d3SPiotr Jasiukajtis * we have
395b2ba9d3SPiotr Jasiukajtis * asinh(x) := x if 1+x*x == 1,
405b2ba9d3SPiotr Jasiukajtis * := sign(x)*(log(x)+ln2)) for large |x|, else
415b2ba9d3SPiotr Jasiukajtis * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x| > 2, else
425b2ba9d3SPiotr Jasiukajtis * := sign(x)*log1p(|x|+x^2/(1+sqrt(1+x^2)))
435b2ba9d3SPiotr Jasiukajtis */
445b2ba9d3SPiotr Jasiukajtis /* INDENT ON */
455b2ba9d3SPiotr Jasiukajtis
465b2ba9d3SPiotr Jasiukajtis #include "libm_macros.h"
475b2ba9d3SPiotr Jasiukajtis #include <math.h>
485b2ba9d3SPiotr Jasiukajtis
495b2ba9d3SPiotr Jasiukajtis static const double xxx[] = {
505b2ba9d3SPiotr Jasiukajtis /* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */
515b2ba9d3SPiotr Jasiukajtis /* ln2 */ 6.93147180559945286227e-01, /* 3FE62E42, FEFA39EF */
525b2ba9d3SPiotr Jasiukajtis /* huge */ 1.00000000000000000000e+300
535b2ba9d3SPiotr Jasiukajtis };
545b2ba9d3SPiotr Jasiukajtis #define one xxx[0]
555b2ba9d3SPiotr Jasiukajtis #define ln2 xxx[1]
565b2ba9d3SPiotr Jasiukajtis #define huge xxx[2]
575b2ba9d3SPiotr Jasiukajtis
585b2ba9d3SPiotr Jasiukajtis double
asinh(double x)595b2ba9d3SPiotr Jasiukajtis asinh(double x) {
605b2ba9d3SPiotr Jasiukajtis double t, w;
615b2ba9d3SPiotr Jasiukajtis int hx, ix;
625b2ba9d3SPiotr Jasiukajtis
635b2ba9d3SPiotr Jasiukajtis hx = ((int *) &x)[HIWORD];
645b2ba9d3SPiotr Jasiukajtis ix = hx & 0x7fffffff;
655b2ba9d3SPiotr Jasiukajtis if (ix >= 0x7ff00000)
665b2ba9d3SPiotr Jasiukajtis #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
675b2ba9d3SPiotr Jasiukajtis return (ix >= 0x7ff80000 ? x : x + x);
685b2ba9d3SPiotr Jasiukajtis /* assumes sparc-like QNaN */
695b2ba9d3SPiotr Jasiukajtis #else
705b2ba9d3SPiotr Jasiukajtis return (x + x); /* x is inf or NaN */
715b2ba9d3SPiotr Jasiukajtis #endif
725b2ba9d3SPiotr Jasiukajtis if (ix < 0x3e300000) { /* |x|<2**-28 */
735b2ba9d3SPiotr Jasiukajtis if (huge + x > one)
745b2ba9d3SPiotr Jasiukajtis return (x); /* return x inexact except 0 */
755b2ba9d3SPiotr Jasiukajtis }
765b2ba9d3SPiotr Jasiukajtis if (ix > 0x41b00000) { /* |x| > 2**28 */
775b2ba9d3SPiotr Jasiukajtis w = log(fabs(x)) + ln2;
785b2ba9d3SPiotr Jasiukajtis } else if (ix > 0x40000000) {
795b2ba9d3SPiotr Jasiukajtis /* 2**28 > |x| > 2.0 */
805b2ba9d3SPiotr Jasiukajtis t = fabs(x);
815b2ba9d3SPiotr Jasiukajtis w = log(2.0 * t + one / (sqrt(x * x + one) + t));
825b2ba9d3SPiotr Jasiukajtis } else {
835b2ba9d3SPiotr Jasiukajtis /* 2.0 > |x| > 2**-28 */
845b2ba9d3SPiotr Jasiukajtis t = x * x;
855b2ba9d3SPiotr Jasiukajtis w = log1p(fabs(x) + t / (one + sqrt(one + t)));
865b2ba9d3SPiotr Jasiukajtis }
875b2ba9d3SPiotr Jasiukajtis return (hx > 0 ? w : -w);
885b2ba9d3SPiotr Jasiukajtis }
89