1/* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * This file is based on work under the following copyright and permission 16 * notice: 17 * 18 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 19 * 20 * Developed at SunSoft, a Sun Microsystems, Inc. business. 21 * Permission to use, copy, modify, and distribute this 22 * software is freely granted, provided that this notice 23 * is preserved. 24 * 25 * @(#)e_acosh.c 1.3 95/01/18 26 */ 27 28#include "jerry-libm-internal.h" 29 30/* acosh(x) 31 * Method : 32 * Based on 33 * acosh(x) = log [ x + sqrt(x * x - 1) ] 34 * we have 35 * acosh(x) := log(x) + ln2, if x is large; else 36 * acosh(x) := log(2x - 1 / (sqrt(x * x - 1) + x)), if x > 2; else 37 * acosh(x) := log1p(t + sqrt(2.0 * t + t * t)); where t = x - 1. 38 * 39 * Special cases: 40 * acosh(x) is NaN with signal if x < 1. 41 * acosh(NaN) is NaN without signal. 42 */ 43 44#define one 1.0 45#define ln2 6.93147180559945286227e-01 /* 0x3FE62E42, 0xFEFA39EF */ 46 47double 48acosh (double x) 49{ 50 double t; 51 int hx; 52 hx = __HI (x); 53 if (hx < 0x3ff00000) 54 { 55 /* x < 1 */ 56 return NAN; 57 } 58 else if (hx >= 0x41b00000) 59 { 60 /* x > 2**28 */ 61 if (hx >= 0x7ff00000) 62 { 63 /* x is inf of NaN */ 64 return x + x; 65 } 66 else 67 { 68 /* acosh(huge) = log(2x) */ 69 return log (x) + ln2; 70 } 71 } 72 else if (((hx - 0x3ff00000) | __LO (x)) == 0) 73 { 74 /* acosh(1) = 0 */ 75 return 0.0; 76 } 77 else if (hx > 0x40000000) 78 { 79 /* 2**28 > x > 2 */ 80 t = x * x; 81 return log (2.0 * x - one / (x + sqrt (t - one))); 82 } 83 else 84 { 85 /* 1 < x < 2 */ 86 t = x - one; 87 return log1p (t + sqrt (2.0 * t + t * t)); 88 } 89} /* acosh */ 90 91#undef one 92#undef ln2 93