From 9c7a699d10ff5cc9e341d1e7cd8d3f48349e4332 Mon Sep 17 00:00:00 2001 From: Rafal Walczyna Date: Mon, 20 Apr 2020 15:41:06 +0200 Subject: [PATCH] Implement missing Math Inverse Hyperbolic functions (#3675) Math.acosh, Math.asinh, Math.acosh C implementation ported from fdlibm Part of Issue #3568 JerryScript-DCO-1.0-Signed-off-by: Rafal Walczyna r.walczyna@samsung.com --- .../ecma/builtin-objects/ecma-builtin-math.c | 12 --- jerry-libm/acosh.c | 92 ++++++++++++++++ jerry-libm/asinh.c | 95 +++++++++++++++++ jerry-libm/atanh.c | 100 ++++++++++++++++++ jerry-libm/include/math.h | 5 + jerry-libm/jerry-libm-internal.h | 4 + tests/jerry/es2015/math-acosh.js | 29 +++++ tests/jerry/es2015/math-asinh.js | 29 +++++ tests/jerry/es2015/math-atanh.js | 32 ++++++ tests/unit-libm/test-libm.inc.h | 81 ++++++++++++++ tools/unit-tests/gen-test-libm.c | 87 +++++++++++++++ 11 files changed, 554 insertions(+), 12 deletions(-) create mode 100644 jerry-libm/acosh.c create mode 100644 jerry-libm/asinh.c create mode 100644 jerry-libm/atanh.c create mode 100644 tests/jerry/es2015/math-acosh.js create mode 100644 tests/jerry/es2015/math-asinh.js create mode 100644 tests/jerry/es2015/math-atanh.js diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-math.c b/jerry-core/ecma/builtin-objects/ecma-builtin-math.c index f7bf2abec..9c389baec 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-math.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-math.c @@ -525,29 +525,17 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w #if ENABLED (JERRY_ES2015) case ECMA_MATH_OBJECT_ACOSH: { -#ifdef JERRY_LIBM_MATH_H - return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Math.acosh")); -#else /* !JERRY_LIBM_MATH_H */ x = DOUBLE_TO_ECMA_NUMBER_T (acosh (x)); -#endif /* JERRY_LIBM_MATH_H */ break; } case ECMA_MATH_OBJECT_ASINH: { -#ifdef JERRY_LIBM_MATH_H - return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Math.asinh")); -#else /* !JERRY_LIBM_MATH_H */ x = DOUBLE_TO_ECMA_NUMBER_T (asinh (x)); -#endif /* JERRY_LIBM_MATH_H */ break; } case ECMA_MATH_OBJECT_ATANH: { -#ifdef JERRY_LIBM_MATH_H - return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Math.atanh")); -#else /* !JERRY_LIBM_MATH_H */ x = DOUBLE_TO_ECMA_NUMBER_T (atanh (x)); -#endif /* JERRY_LIBM_MATH_H */ break; } case ECMA_MATH_OBJECT_CBRT: diff --git a/jerry-libm/acosh.c b/jerry-libm/acosh.c new file mode 100644 index 000000000..7201f4f2b --- /dev/null +++ b/jerry-libm/acosh.c @@ -0,0 +1,92 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is based on work under the following copyright and permission + * notice: + * + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * + * @(#)e_acosh.c 1.3 95/01/18 + */ + +#include "jerry-libm-internal.h" + +/* acosh(x) + * Method : + * Based on + * acosh(x) = log [ x + sqrt(x * x - 1) ] + * we have + * acosh(x) := log(x) + ln2, if x is large; else + * acosh(x) := log(2x - 1 / (sqrt(x * x - 1) + x)), if x > 2; else + * acosh(x) := log1p(t + sqrt(2.0 * t + t * t)); where t = x - 1. + * + * Special cases: + * acosh(x) is NaN with signal if x < 1. + * acosh(NaN) is NaN without signal. + */ + +#define one 1.0 +#define ln2 6.93147180559945286227e-01 /* 0x3FE62E42, 0xFEFA39EF */ + +double +acosh (double x) +{ + double t; + int hx; + hx = __HI (x); + if (hx < 0x3ff00000) + { + /* x < 1 */ + return NAN; + } + else if (hx >= 0x41b00000) + { + /* x > 2**28 */ + if (hx >= 0x7ff00000) + { + /* x is inf of NaN */ + return x + x; + } + else + { + /* acosh(huge) = log(2x) */ + return log (x) + ln2; + } + } + else if (((hx - 0x3ff00000) | __LO (x)) == 0) + { + /* acosh(1) = 0 */ + return 0.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)); + } +} /* acosh */ + +#undef one +#undef ln2 diff --git a/jerry-libm/asinh.c b/jerry-libm/asinh.c new file mode 100644 index 000000000..17edbec75 --- /dev/null +++ b/jerry-libm/asinh.c @@ -0,0 +1,95 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is based on work under the following copyright and permission + * notice: + * + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * + * @(#)s_asinh.c 1.3 95/01/18 + */ + +#include "jerry-libm-internal.h" + +/* asinh(x) + * Method : + * Based on + * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] + * we have + * asinh(x) := x if 1 + x * x = 1, + * := sign(x) * (log(x)+ln2)) for large |x|, else + * := sign(x) * log(2|x| + 1 / (|x| + sqrt(x * x + 1))) if|x| > 2, else + * := sign(x) * log1p(|x| + x^2 / (1 + sqrt(1 + x^2))) + */ + +#define one 1.0 +#define ln2 6.93147180559945286227e-01 /* 0x3FE62E42, 0xFEFA39EF */ +#define huge 1.0e+300 + +double +asinh (double x) +{ + double t, w; + int hx, ix; + hx = __HI (x); + ix = hx & 0x7fffffff; + if (ix >= 0x7ff00000) + { + /* x is inf or NaN */ + return x + x; + } + if (ix < 0x3e300000) + { + /* |x| < 2**-28 */ + if (huge + x > one) + { + /* return x inexact except 0 */ + return x; + } + } + if (ix > 0x41b00000) + { + /* |x| > 2**28 */ + w = log (fabs (x)) + ln2; + } + else if (ix > 0x40000000) + { + /* 2**28 > |x| > 2.0 */ + t = fabs (x); + w = log (2.0 * t + one / (sqrt (x * x + one) + t)); + } + else + { + /* 2.0 > |x| > 2**-28 */ + t = x * x; + w = log1p (fabs (x) + t / (one + sqrt (one + t))); + } + if (hx > 0) + { + return w; + } + else + { + return -w; + } +} /* asinh */ + +#undef one +#undef ln2 +#undef huge diff --git a/jerry-libm/atanh.c b/jerry-libm/atanh.c new file mode 100644 index 000000000..6053d01f0 --- /dev/null +++ b/jerry-libm/atanh.c @@ -0,0 +1,100 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is based on work under the following copyright and permission + * notice: + * + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * + * @(#)e_atanh.c 1.3 95/01/18 + */ + +#include "jerry-libm-internal.h" + +/* atanh(x) + * Method : + * 1.Reduced x to positive by atanh(-x) = -atanh(x) + * 2.For x >= 0.5 + * 1 2x x + * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) + * 2 1 - x 1 - x + * + * For x < 0.5 +* atanh(x) = 0.5 * log1p(2x + 2x * x / (1 - x)) + * + * Special cases: + * atanh(x) is NaN if |x| > 1 with signal; + * atanh(NaN) is that NaN with no signal; + * atanh(+-1) is +-INF with signal. + * + */ + +#define zero 0.0 +#define one 1.0 +#define huge 1.0e+300 + +double +atanh (double x) +{ + double t; + int hx, ix; + double_accessor temp; + temp.dbl = x; + hx = temp.as_int.hi; + ix = hx & 0x7fffffff; + + /* |x| > 1 */ + if ((ix | ((unsigned int)(temp.as_int.lo | (-temp.as_int.lo)) >> 31)) > 0x3ff00000) + { + return NAN; + } + if (ix == 0x3ff00000) + { + return x / zero; + } + if (ix < 0x3e300000 && (huge + x) > zero) + { + return x; /* x<2**-28 */ + } + + /* x <- |x| */ + temp.as_int.hi = ix; + if (ix < 0x3fe00000) + { + /* x < 0.5 */ + t = temp.dbl + temp.dbl; + t = 0.5 * log1p (t + t * temp.dbl / (one - temp.dbl)); + } + else + { + t = 0.5 * log1p ((temp.dbl + temp.dbl) / (one - temp.dbl)); + } + if (hx >= 0) + { + return t; + } + else + { + return -t; + } +} /* atanh */ + +#undef zero +#undef one +#undef huge diff --git a/jerry-libm/include/math.h b/jerry-libm/include/math.h index d3b391699..71d778eef 100644 --- a/jerry-libm/include/math.h +++ b/jerry-libm/include/math.h @@ -56,6 +56,11 @@ double asin (double); double atan (double); double atan2 (double, double); +/* Inverse hyperbolic functions */ +double acosh (double); +double asinh (double); +double atanh (double); + /* Exponential and logarithmic functions. */ double exp (double); double expm1 (double); diff --git a/jerry-libm/jerry-libm-internal.h b/jerry-libm/jerry-libm-internal.h index 7ed7579bf..b87519200 100644 --- a/jerry-libm/jerry-libm-internal.h +++ b/jerry-libm/jerry-libm-internal.h @@ -88,6 +88,10 @@ double cos (double x); double sin (double x); double tan (double x); +double acosh (double x); +double asinh (double x); +double atanh (double x); + double exp (double x); double expm1 (double x); double log (double x); diff --git a/tests/jerry/es2015/math-acosh.js b/tests/jerry/es2015/math-acosh.js new file mode 100644 index 000000000..bdda500cf --- /dev/null +++ b/tests/jerry/es2015/math-acosh.js @@ -0,0 +1,29 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var nan = NaN; +var p_zero = 0.0; +var m_zero = -p_zero; + +function isSameZero (x, y) +{ + return x === 0 && (1 / x) === (1 / y); +} + +assert(isNaN(Math.acosh(NaN))); +assert(isNaN(Math.acosh(0))); +assert(isNaN(Math.acosh(Number.NEGATIVE_INFINITY))); +assert(isSameZero(Math.acosh(1), p_zero)); +assert(Math.acosh(Number.POSITIVE_INFINITY) === Number.POSITIVE_INFINITY); + diff --git a/tests/jerry/es2015/math-asinh.js b/tests/jerry/es2015/math-asinh.js new file mode 100644 index 000000000..af4d2dd67 --- /dev/null +++ b/tests/jerry/es2015/math-asinh.js @@ -0,0 +1,29 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var nan = NaN; +var p_zero = 0.0; +var m_zero = -p_zero; + +function isSameZero (x, y) +{ + return x === 0 && (1 / x) === (1 / y); +} + +assert(isNaN(Math.asinh(NaN))); +assert(isSameZero(Math.asinh(p_zero), p_zero)); +assert(isSameZero(Math.asinh(m_zero), m_zero)); +assert(Math.asinh(Number.POSITIVE_INFINITY) === Number.POSITIVE_INFINITY); +assert(Math.asinh(Number.NEGATIVE_INFINITY) === Number.NEGATIVE_INFINITY); + diff --git a/tests/jerry/es2015/math-atanh.js b/tests/jerry/es2015/math-atanh.js new file mode 100644 index 000000000..7d37f70a7 --- /dev/null +++ b/tests/jerry/es2015/math-atanh.js @@ -0,0 +1,32 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var nan = NaN; +var p_zero = 0.0; +var m_zero = -p_zero; + +function isSameZero (x, y) +{ + return x === 0 && (1 / x) === (1 / y); +} + +assert(isNaN(Math.atanh(NaN))); +assert(isNaN(Math.atanh(2))); +assert(isNaN(Math.atanh(44))); +assert(isNaN(Math.atanh(-2))); +assert(isNaN(Math.atanh(-13))); +assert(isSameZero(Math.atanh(p_zero), p_zero)); +assert(isSameZero(Math.atanh(m_zero), m_zero)); +assert(Math.atanh(-1) === Number.NEGATIVE_INFINITY); +assert(Math.atanh(1) === Number.POSITIVE_INFINITY); diff --git a/tests/unit-libm/test-libm.inc.h b/tests/unit-libm/test-libm.inc.h index edbcf0cc7..48bd7f764 100644 --- a/tests/unit-libm/test-libm.inc.h +++ b/tests/unit-libm/test-libm.inc.h @@ -167,6 +167,87 @@ check_double ("atan2 (0.7, -1.0)", atan2 (0.7, -1.0), 2.53086668920058466270E+00 check_double ("atan2 (-0.7, -1.0)", atan2 (-0.7, -1.0), -2.53086668920058466270E+00); check_double ("atan2 (0.4, 0.0003)", atan2 (0.4, 0.0003), 1.57004632693552159672E+00); check_double ("atan2 (1.4, -0.93)", atan2 (1.4, -0.93), 2.15714876682378431383E+00); +check_double ("acosh (0.0)", acosh (0.0), -NAN); +check_double ("acosh (-0.0)", acosh (-0.0), -NAN); +check_double ("acosh (1.0)", acosh (1.0), 0.00000000000000000000E+00); +check_double ("acosh (-1.0)", acosh (-1.0), -NAN); +check_double ("acosh (INFINITY)", acosh (INFINITY), INF); +check_double ("acosh (-INFINITY)", acosh (-INFINITY), -NAN); +check_double ("acosh (NAN)", acosh (NAN), NAN); +check_double ("acosh (7.08e+02)", acosh (7.08e+02), 7.25559077551410425144E+00); +check_double ("acosh (7.10e+02)", acosh (7.10e+02), 7.25841165466159132791E+00); +check_double ("acosh (-7.40e+02)", acosh (-7.40e+02), -NAN); +check_double ("acosh (-7.50e+02)", acosh (-7.50e+02), -NAN); +check_double ("acosh (0.34)", acosh (0.34), -NAN); +check_double ("acosh (-0.34)", acosh (-0.34), -NAN); +check_double ("acosh (0.35)", acosh (0.35), -NAN); +check_double ("acosh (-0.35)", acosh (-0.35), -NAN); +check_double ("acosh (1.03)", acosh (1.03), 2.44340698822827606662E-01); +check_double ("acosh (-1.03)", acosh (-1.03), -NAN); +check_double ("acosh (1.04)", acosh (1.04), 2.81908289054146887764E-01); +check_double ("acosh (-1.04)", acosh (-1.04), -NAN); +check_double ("acosh (3.72e-09)", acosh (3.72e-09), -NAN); +check_double ("acosh (-3.72e-09)", acosh (-3.72e-09), -NAN); +check_double ("acosh (3.73e-09)", acosh (3.73e-09), -NAN); +check_double ("acosh (-3.73e-09)", acosh (-3.73e-09), -NAN); +check_double ("acosh (2.0)", acosh (2.0), 1.31695789692481679545E+00); +check_double ("acosh (3.0)", acosh (3.0), 1.76274717403908609548E+00); +check_double ("acosh (0.7)", acosh (0.7), -NAN); +check_double ("acosh (38.0)", acosh (38.0), 4.33056016511402308566E+00); +check_double ("asinh (0.0)", asinh (0.0), 0.00000000000000000000E+00); +check_double ("asinh (-0.0)", asinh (-0.0), -0.00000000000000000000E+00); +check_double ("asinh (1.0)", asinh (1.0), 8.81373587019543047738E-01); +check_double ("asinh (-1.0)", asinh (-1.0), -8.81373587019543047738E-01); +check_double ("asinh (INFINITY)", asinh (INFINITY), INF); +check_double ("asinh (-INFINITY)", asinh (-INFINITY), -INF); +check_double ("asinh (NAN)", asinh (NAN), NAN); +check_double ("asinh (7.08e+02)", asinh (7.08e+02), 7.25559177299247970439E+00); +check_double ("asinh (7.10e+02)", asinh (7.10e+02), 7.25841264652828410675E+00); +check_double ("asinh (-7.40e+02)", asinh (-7.40e+02), -7.29979782329546722508E+00); +check_double ("asinh (-7.50e+02)", asinh (-7.50e+02), -7.31322083153444957304E+00); +check_double ("asinh (0.34)", asinh (0.34), 3.33768351645882199730E-01); +check_double ("asinh (-0.34)", asinh (-0.34), -3.33768351645882199730E-01); +check_double ("asinh (0.35)", asinh (0.35), 3.43221555085943930141E-01); +check_double ("asinh (-0.35)", asinh (-0.35), -3.43221555085943930141E-01); +check_double ("asinh (1.03)", asinh (1.03), 9.02428495530461671770E-01); +check_double ("asinh (-1.03)", asinh (-1.03), -9.02428495530461671770E-01); +check_double ("asinh (1.04)", asinh (1.04), 9.09376928017844976537E-01); +check_double ("asinh (-1.04)", asinh (-1.04), -9.09376928017844976537E-01); +check_double ("asinh (3.72e-09)", asinh (3.72e-09), 3.71999999999999997526E-09); +check_double ("asinh (-3.72e-09)", asinh (-3.72e-09), -3.71999999999999997526E-09); +check_double ("asinh (3.73e-09)", asinh (3.73e-09), 3.73000000000000014752E-09); +check_double ("asinh (-3.73e-09)", asinh (-3.73e-09), -3.73000000000000014752E-09); +check_double ("asinh (2.0)", asinh (2.0), 1.44363547517881030124E+00); +check_double ("asinh (3.0)", asinh (3.0), 1.81844645923206682525E+00); +check_double ("asinh (0.7)", asinh (0.7), 6.52666566082355736889E-01); +check_double ("asinh (38.0)", asinh (38.0), 4.33090642553643068169E+00); +check_double ("atanh (0.0)", atanh (0.0), 0.00000000000000000000E+00); +check_double ("atanh (-0.0)", atanh (-0.0), -0.00000000000000000000E+00); +check_double ("atanh (1.0)", atanh (1.0), INF); +check_double ("atanh (-1.0)", atanh (-1.0), -INF); +check_double ("atanh (INFINITY)", atanh (INFINITY), -NAN); +check_double ("atanh (-INFINITY)", atanh (-INFINITY), -NAN); +check_double ("atanh (NAN)", atanh (NAN), NAN); +check_double ("atanh (7.08e+02)", atanh (7.08e+02), -NAN); +check_double ("atanh (7.10e+02)", atanh (7.10e+02), -NAN); +check_double ("atanh (-7.40e+02)", atanh (-7.40e+02), -NAN); +check_double ("atanh (-7.50e+02)", atanh (-7.50e+02), -NAN); +check_double ("atanh (0.34)", atanh (0.34), 3.54092528962242913959E-01); +check_double ("atanh (-0.34)", atanh (-0.34), -3.54092528962242913959E-01); +check_double ("atanh (0.35)", atanh (0.35), 3.65443754271396137323E-01); +check_double ("atanh (-0.35)", atanh (-0.35), -3.65443754271396137323E-01); +check_double ("atanh (1.03)", atanh (1.03), -NAN); +check_double ("atanh (-1.03)", atanh (-1.03), -NAN); +check_double ("atanh (1.04)", atanh (1.04), -NAN); +check_double ("atanh (-1.04)", atanh (-1.04), -NAN); +check_double ("atanh (3.72e-09)", atanh (3.72e-09), 3.71999999999999997526E-09); +check_double ("atanh (-3.72e-09)", atanh (-3.72e-09), -3.71999999999999997526E-09); +check_double ("atanh (3.73e-09)", atanh (3.73e-09), 3.73000000000000014752E-09); +check_double ("atanh (-3.73e-09)", atanh (-3.73e-09), -3.73000000000000014752E-09); +check_double ("atanh (2.0)", atanh (2.0), -NAN); +check_double ("atanh (3.0)", atanh (3.0), -NAN); +check_double ("atanh (0.7)", atanh (0.7), 8.67300527694053080552E-01); +check_double ("atanh (38.0)", atanh (38.0), -NAN); check_double ("ceil (0.0)", ceil (0.0), 0.00000000000000000000E+00); check_double ("ceil (-0.0)", ceil (-0.0), -0.00000000000000000000E+00); check_double ("ceil (INFINITY)", ceil (INFINITY), INF); diff --git a/tools/unit-tests/gen-test-libm.c b/tools/unit-tests/gen-test-libm.c index ee2ffaae5..19ca411e1 100644 --- a/tools/unit-tests/gen-test-libm.c +++ b/tools/unit-tests/gen-test-libm.c @@ -210,6 +210,93 @@ main (int argc, char **args) GEN_DBL_TEST (atan2 (0.4, 0.0003)); GEN_DBL_TEST (atan2 (1.4, -0.93)); + /* acosh tests */ + GEN_DBL_TEST (acosh (0.0)); + GEN_DBL_TEST (acosh (-0.0)); + GEN_DBL_TEST (acosh (1.0)); + GEN_DBL_TEST (acosh (-1.0)); + GEN_DBL_TEST (acosh (INFINITY)); + GEN_DBL_TEST (acosh (-INFINITY)); + GEN_DBL_TEST (acosh (NAN)); + GEN_DBL_TEST (acosh (7.08e+02)); + GEN_DBL_TEST (acosh (7.10e+02)); + GEN_DBL_TEST (acosh (-7.40e+02)); + GEN_DBL_TEST (acosh (-7.50e+02)); + GEN_DBL_TEST (acosh (0.34)); + GEN_DBL_TEST (acosh (-0.34)); + GEN_DBL_TEST (acosh (0.35)); + GEN_DBL_TEST (acosh (-0.35)); + GEN_DBL_TEST (acosh (1.03)); + GEN_DBL_TEST (acosh (-1.03)); + GEN_DBL_TEST (acosh (1.04)); + GEN_DBL_TEST (acosh (-1.04)); + GEN_DBL_TEST (acosh (3.72e-09)); + GEN_DBL_TEST (acosh (-3.72e-09)); + GEN_DBL_TEST (acosh (3.73e-09)); + GEN_DBL_TEST (acosh (-3.73e-09)); + GEN_DBL_TEST (acosh (2.0)); + GEN_DBL_TEST (acosh (3.0)); + GEN_DBL_TEST (acosh (0.7)); + GEN_DBL_TEST (acosh (38.0)); + + /* asinh tests */ + GEN_DBL_TEST (asinh (0.0)); + GEN_DBL_TEST (asinh (-0.0)); + GEN_DBL_TEST (asinh (1.0)); + GEN_DBL_TEST (asinh (-1.0)); + GEN_DBL_TEST (asinh (INFINITY)); + GEN_DBL_TEST (asinh (-INFINITY)); + GEN_DBL_TEST (asinh (NAN)); + GEN_DBL_TEST (asinh (7.08e+02)); + GEN_DBL_TEST (asinh (7.10e+02)); + GEN_DBL_TEST (asinh (-7.40e+02)); + GEN_DBL_TEST (asinh (-7.50e+02)); + GEN_DBL_TEST (asinh (0.34)); + GEN_DBL_TEST (asinh (-0.34)); + GEN_DBL_TEST (asinh (0.35)); + GEN_DBL_TEST (asinh (-0.35)); + GEN_DBL_TEST (asinh (1.03)); + GEN_DBL_TEST (asinh (-1.03)); + GEN_DBL_TEST (asinh (1.04)); + GEN_DBL_TEST (asinh (-1.04)); + GEN_DBL_TEST (asinh (3.72e-09)); + GEN_DBL_TEST (asinh (-3.72e-09)); + GEN_DBL_TEST (asinh (3.73e-09)); + GEN_DBL_TEST (asinh (-3.73e-09)); + GEN_DBL_TEST (asinh (2.0)); + GEN_DBL_TEST (asinh (3.0)); + GEN_DBL_TEST (asinh (0.7)); + GEN_DBL_TEST (asinh (38.0)); + + /* atanh tests */ + GEN_DBL_TEST (atanh (0.0)); + GEN_DBL_TEST (atanh (-0.0)); + GEN_DBL_TEST (atanh (1.0)); + GEN_DBL_TEST (atanh (-1.0)); + GEN_DBL_TEST (atanh (INFINITY)); + GEN_DBL_TEST (atanh (-INFINITY)); + GEN_DBL_TEST (atanh (NAN)); + GEN_DBL_TEST (atanh (7.08e+02)); + GEN_DBL_TEST (atanh (7.10e+02)); + GEN_DBL_TEST (atanh (-7.40e+02)); + GEN_DBL_TEST (atanh (-7.50e+02)); + GEN_DBL_TEST (atanh (0.34)); + GEN_DBL_TEST (atanh (-0.34)); + GEN_DBL_TEST (atanh (0.35)); + GEN_DBL_TEST (atanh (-0.35)); + GEN_DBL_TEST (atanh (1.03)); + GEN_DBL_TEST (atanh (-1.03)); + GEN_DBL_TEST (atanh (1.04)); + GEN_DBL_TEST (atanh (-1.04)); + GEN_DBL_TEST (atanh (3.72e-09)); + GEN_DBL_TEST (atanh (-3.72e-09)); + GEN_DBL_TEST (atanh (3.73e-09)); + GEN_DBL_TEST (atanh (-3.73e-09)); + GEN_DBL_TEST (atanh (2.0)); + GEN_DBL_TEST (atanh (3.0)); + GEN_DBL_TEST (atanh (0.7)); + GEN_DBL_TEST (atanh (38.0)); + /* ceil tests */ GEN_DBL_TEST (ceil (0.0)); GEN_DBL_TEST (ceil (-0.0));