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 0000000000000000000000000000000000000000..ea5d1fd42c4940a32c01657589d63ac84c1cd03c --- /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 b125f9dd4741ebe64445ce4df9a1da409236e260..8671519e8c6edcfdabbefd7768de7b9be2937415 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 fd262f9e8c6c1b798504612e7c211f3a6a3f995d..14265b946162fcf769a04cc86d8e7a026533e05f 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); }