From b2b68c7be35712ac5dd222888e09e3207d71a4fd Mon Sep 17 00:00:00 2001 From: liujunhui Date: Tue, 26 Aug 2025 16:23:16 +0800 Subject: [PATCH] =?UTF-8?q?description=20[Bug]:=20Math.pow=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8C1.0=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit intrinsics.cpp文件中对于powF64函数新增边界判断,添加单元测试用例PowTest.ets Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICUVAB Signed-off-by: liujunhui27@huawei.com --- .../tests/ets_func_tests/std/math/PowTest.ets | 32 +++++++++++++++++++ .../escompat/list.escompat_Math_exp.yaml | 4 +-- static_core/runtime/intrinsics.cpp | 4 +++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 static_core/plugins/ets/tests/ets_func_tests/std/math/PowTest.ets diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/math/PowTest.ets b/static_core/plugins/ets/tests/ets_func_tests/std/math/PowTest.ets new file mode 100644 index 0000000000..ea5d1fd42c --- /dev/null +++ b/static_core/plugins/ets/tests/ets_func_tests/std/math/PowTest.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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, + * 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. + */ + +const nan = Double.NaN; +const posInf = Double.POSITIVE_INFINITY; +const negInf = Double.NEGATIVE_INFINITY; + +function test_power_nan() { + // |x| = 1 且 y = ±∞ → NaN + arktest.assertTrue(Double.isNaN(power(1.0, posInf)), "power(1.0, +∞) should be NaN"); + arktest.assertTrue(Double.isNaN(power(-1.0, posInf)), "power(-1.0, +∞) should be NaN"); + arktest.assertTrue(Double.isNaN(power(1.0, negInf)), "power(1.0, -∞) should be NaN"); + arktest.assertTrue(Double.isNaN(power(-1.0, negInf)), "power(-1.0, -∞) should be NaN"); +} + +function main(): int { + let powerTestsuite = new arktest.ArkTestsuite("powerTest"); + powerTestsuite.addTest("test_power_nan", test_power_nan); + return powerTestsuite.run(); +} diff --git a/static_core/plugins/ets/tests/stdlib-templates/escompat/list.escompat_Math_exp.yaml b/static_core/plugins/ets/tests/stdlib-templates/escompat/list.escompat_Math_exp.yaml index b125f9dd47..8671519e8c 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/escompat/list.escompat_Math_exp.yaml +++ b/static_core/plugins/ets/tests/stdlib-templates/escompat/list.escompat_Math_exp.yaml @@ -110,8 +110,8 @@ test6: doubleInf, test7: doubleInf, test8: 0.0, - test9: 1.0, - test10: 1.0, + test9: doubleNaN, + test10: doubleNaN, test11: doubleNaN, }, } diff --git a/static_core/runtime/intrinsics.cpp b/static_core/runtime/intrinsics.cpp index fd262f9e8c..14265b9461 100644 --- a/static_core/runtime/intrinsics.cpp +++ b/static_core/runtime/intrinsics.cpp @@ -98,6 +98,10 @@ float PowF32(float base, float exp) double PowF64(double base, double exp) { + // If abs(x) is 1 and y is inf or -inf, the result is NaN + if (std::abs(base) == 1 && !std::isfinite(exp)) { + return coretypes::TaggedValue::VALUE_NAN; + } return std::pow(base, exp); } -- Gitee