• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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 #ifndef ECMASCRIPT_BASE_MATH_HELPER_H
17 #define ECMASCRIPT_BASE_MATH_HELPER_H
18 
19 #include <cstdint>
20 #include <cmath>
21 
22 #define panda_bit_utils_ctz __builtin_ctz      // NOLINT(cppcoreguidelines-macro-usage)
23 #define panda_bit_utils_ctzll __builtin_ctzll  // NOLINT(cppcoreguidelines-macro-usage)
24 
25 namespace panda::ecmascript::base {
26 class MathHelper {
27 public:
GetIntLog2(const uint32_t X)28     static constexpr uint32_t GetIntLog2(const uint32_t X)
29     {
30         return static_cast<uint32_t>(panda_bit_utils_ctz(X));
31     }
32 
GetIntLog2(const uint64_t X)33     static constexpr uint64_t GetIntLog2(const uint64_t X)
34     {
35         return static_cast<uint64_t>(panda_bit_utils_ctzll(X));
36     }
37 
Asinh(double input)38     static double Asinh(double input)
39     {
40 #if defined(PANDA_TARGET_WINDOWS)
41         if (input == 0 && !std::signbit(input)) {
42             // +0.0(double) is the special case for std::asinh() function compiled in linux for windows.
43             return +0.0;
44         }
45 #endif
46         return std::asinh(input);
47     }
48 
Atanh(double input)49     static inline double Atanh(double input)
50     {
51 #if defined(PANDA_TARGET_WINDOWS)
52         if (input == 0 && std::signbit(input)) {
53             // -0.0(double) is the special case for std::atanh() function compiled in linux for windows.
54             return -0.0;
55         }
56 #endif
57         return std::atanh(input);
58     }
59 };
60 }  // panda::ecmascript::base
61 
62 #endif  // ECMASCRIPT_BASE_MATH_HELPER_H
63