1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 16#include "ecmascript/base/math_helper.h" 17#include "ecmascript/tests/test_helper.h" 18 19using namespace panda::ecmascript; 20using namespace panda::ecmascript::base; 21 22namespace panda::test { 23class MathHelperTest : public BaseTestWithScope<false> { 24}; 25 26HWTEST_F_L0(MathHelperTest, GetIntLog2_001) 27{ 28 const uint32_t commonInput = static_cast<uint32_t>(0b111111111) << 13; // 13 : left shift digit 29 const uint32_t maxInput = std::numeric_limits<uint32_t>::max(); 30 EXPECT_EQ(MathHelper::GetIntLog2(commonInput), 13U); 31 EXPECT_EQ(MathHelper::GetIntLog2(maxInput), 0U); 32} 33 34HWTEST_F_L0(MathHelperTest, GetIntLog2_002) 35{ 36 const uint64_t commonInput = static_cast<uint64_t>(0b111111111) << 53; // 53 : left shift digit 37 const uint64_t maxInput = std::numeric_limits<uint64_t>::max(); 38 EXPECT_EQ(MathHelper::GetIntLog2(commonInput), 53U); 39 EXPECT_EQ(MathHelper::GetIntLog2(maxInput), 0U); 40} 41 42HWTEST_F_L0(MathHelperTest, Asinh) 43{ 44 EXPECT_EQ(MathHelper::Asinh(1), 0.88137358701954302523260932497979); 45 EXPECT_EQ(MathHelper::Asinh(+0), +0.0); 46 EXPECT_EQ(MathHelper::Asinh(-0), -0.0); 47 EXPECT_EQ(MathHelper::Asinh(-1), -0.88137358701954302523260932497979); 48 49 double nanResult = MathHelper::Asinh(std::numeric_limits<double>::signaling_NaN()); 50 EXPECT_TRUE(std::isnan(nanResult)); 51} 52 53HWTEST_F_L0(MathHelperTest, Atanh) 54{ 55 EXPECT_EQ(MathHelper::Atanh(0), 0); 56 EXPECT_EQ(MathHelper::Atanh(0.5), std::atanh(0.5)); 57 58 double infResult = MathHelper::Atanh(-1); // limit value 59 EXPECT_TRUE(std::isinf(infResult)); 60 61 double nanResult = MathHelper::Atanh(2); // out of input range 62 EXPECT_TRUE(std::isnan(nanResult)); 63} 64} // namespace panda::test 65