1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 24 */ 25 26 /* 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 #pragma weak __acosh = acosh 32 33 34 /* 35 * acosh(x) 36 * Method : 37 * Based on 38 * acosh(x) = log [ x + sqrt(x*x-1) ] 39 * we have 40 * acosh(x) := log(x)+ln2, if x is large; else 41 * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x > 2; else 42 * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t = x-1. 43 * 44 * Special cases: 45 * acosh(x) is NaN with signal if x < 1. 46 * acosh(NaN) is NaN without signal. 47 */ 48 49 #include "libm_protos.h" /* _SVID_libm_error */ 50 #include "libm_macros.h" 51 #include <math.h> 52 53 static const double one = 1.0, 54 ln2 = 6.93147180559945286227e-01; /* 3FE62E42, FEFA39EF */ 55 56 double 57 acosh(double x) 58 { 59 double t; 60 int hx; 61 62 hx = ((int *)&x)[HIWORD]; 63 64 if (hx < 0x3ff00000) { /* x < 1 */ 65 if (isnan(x)) 66 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) 67 return (hx >= 0xfff80000 ? x : (x - x) / (x - x)); 68 69 /* assumes sparc-like QNaN */ 70 #else 71 return ((x - x) / (x - x)); 72 #endif 73 else 74 return (_SVID_libm_err(x, x, 29)); 75 } else if (hx >= 0x41b00000) { 76 /* x > 2**28 */ 77 if (hx >= 0x7ff00000) { /* x is inf of NaN */ 78 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) 79 return (hx >= 0x7ff80000 ? x : x + x); 80 /* assumes sparc-like QNaN */ 81 #else 82 return (x + x); 83 #endif 84 } else { /* acosh(huge)=log(2x) */ 85 return (log(x) + ln2); 86 } 87 } else if (((hx - 0x3ff00000) | ((int *)&x)[LOWORD]) == 0) { 88 return (0.0); /* acosh(1) = 0 */ 89 } else if (hx > 0x40000000) { 90 /* 2**28 > x > 2 */ 91 t = x * x; 92 return (log(2.0 * x - one / (x + sqrt(t - one)))); 93 } else { 94 /* 1 < x < 2 */ 95 t = x - one; 96 return (log1p(t + sqrt(2.0 * t + t * t))); 97 } 98 }