1 #ifndef DALI_COMPILE_TIME_MATH_H
2 #define DALI_COMPILE_TIME_MATH_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
26 #include <dali/public-api/common/dali-common.h>
31 * @addtogroup dali_core_math
36 * @brief Compiles time template to calculate base to the power of N.
39 * @tparam mantissa to raise to exponent
40 * @tparam exponent to use for mantissa
41 * @note Values need to be compile time constants.
42 * Usage: <code>Power< 10, 2 >::value; // value=100</code>
44 template<size_t mantissa, size_t exponent>
49 value = mantissa * Power<mantissa, exponent - 1>::value
54 * @brief Compiles time template to calculate base to the power of N.
56 * Specialization for power of 1.
58 * @tparam mantissa to raise to exponent
60 template<size_t mantissa>
61 struct Power<mantissa, 1>
70 * @brief Compiles time template to calculate base to the power of N.
72 * Specialization for power of 0.
74 * @tparam mantissa to raise to exponent
76 template<size_t mantissa>
77 struct Power<mantissa, 0>
86 * @brief Compiles time template to calculate base logarithm of N.
89 * @tparam number for which to calculate the logarithm
90 * @tparam base logarithm to calculate
91 * @note Values need to be compile time constants.
92 * Usage: <code>Log< 100, 10 >::value; value equals 2</code>
94 template<size_t number, size_t base = 2>
99 value = 1 + Log<number / base, base>::value
104 * @brief Compiles time template to calculate base logarithm of N.
106 * Specialization for logarithm of 1.
108 * @tparam base logarithm to calculate
110 template<size_t base>
120 * @brief Compiles time template to calculate base logarithm of N.
122 * Specialization for logarithm of 0.
124 * @tparam base logarithm to calculate
126 template<size_t base>
136 * @brief Compiles time template to calculate the machine epsilon for a given floating point number.
139 * @tparam N the number for which to calculate the machine epsilon
140 * @note Value needs to be compile time constant.
141 * Usage: <code>Epsilon<1000>::value; value equals 0.000119209</code>
146 // take log10 of the number to get to the nearest power of 10 number and divide that by 10
147 // template recursion will take care of the rest
149 static constexpr float value = 10.0f * Epsilon<Power<10, Log<N, 10>::value>::value / 10>::value;
151 static const float value = 10.0f * Epsilon<Power<10, Log<N, 10>::value>::value / 10>::value;
156 * @brief Compiles time template to calculate the machine epsilon for a given floating point number.
158 * Specialization for epsilon of 1.
165 static constexpr float value = FLT_EPSILON;
167 static const float value = FLT_EPSILON;
172 * @brief Compiles time template to calculate the machine epsilon for a given floating point number.
174 * Specialization for epsilon of 0.
181 static constexpr float value = FLT_MIN;
183 static const float value = FLT_MIN;
192 #endif // DALI_COMPILE_TIME_MATH_H