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
This commit is contained in:
Rafal Walczyna
2020-04-20 15:41:06 +02:00
committed by GitHub
parent 453da11398
commit 9c7a699d10
11 changed files with 554 additions and 12 deletions
+29
View File
@@ -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);
+29
View File
@@ -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);
+32
View File
@@ -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);
+81
View File
@@ -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);