1 #ifndef __DALI_COMPILE_TIME_MATH_H__
2 #define __DALI_COMPILE_TIME_MATH_H__
5 * Copyright (c) 2015 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.
25 #include <dali/public-api/common/dali-common.h>
30 * @addtogroup dali_core_math
35 * @brief Compile time template to calculate base to the power of N.
38 * @tparam mantissa to raise to exponent
39 * @tparam N exponent to use for mantissa
40 * @note values need to be compile time constants
41 * Usage: <code>Power< 10, 2 >::value; // value=100</code>
43 template< size_t mantissa, size_t exponent >
46 enum { value = mantissa * Power< mantissa, exponent - 1 >::value };
50 * @brief Compile time template to calculate base to the power of N.
52 * Specialisation for power of 1
54 * @tparam mantissa to raise to exponent
56 template< size_t mantissa >
57 struct Power< mantissa, 1 >
59 enum { value = mantissa };
63 * @brief Compile time template to calculate base to the power of N.
65 * Specialisation for power of 0
67 * @tparam mantissa to raise to exponent
69 template< size_t mantissa >
70 struct Power< mantissa, 0 >
76 * @brief Compile time template to calculate base logarithm of N.
79 * @tparam number for which to calculate the logarithm
80 * @tparam base logarithm to calculate
81 * @note values need to be compile time constants
82 * Usage: <code>Log< 100, 10 >::value; value equals 2</code>
84 template< size_t number, size_t base = 2 >
87 enum { value = 1 + Log< number / base, base >::value };
91 * @brief Compile time template to calculate base logarithm of N.
93 * Specialisation for logarithm of 1
95 * @tparam base logarithm to calculate
97 template< size_t base >
104 * @brief Compile time template to calculate base logarithm of N.
106 * Specialisation for logarithm of 0
108 * @tparam base logarithm to calculate
110 template< size_t base >
111 struct Log< 0, base >
118 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
121 * @tparam N the number for which to calculate the machine epsilon
122 * @note value needs to be compile time constant
123 * Usage: <code>Epsilon<1000>::value; value equals 0.000119209</code>
128 // take log10 of the number to get to the nearest power of 10 number and divide that by 10
129 // template recursion will take care of the rest
131 static constexpr float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
133 static const float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
138 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
140 * Specialisation for epsilon of 1
141 * predefined value calculated on ARM Cortex A9 target
148 static constexpr float value = 1.19209e-07f;
150 static const float value = 1.19209e-07f;
155 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
157 * Specialisation for epsilon of 0
158 * predefined value calculated on ARM Cortex A9 target
165 static constexpr float value = 1.4013e-45f;
167 static const float value = 1.4013e-45f;
176 #endif // __DALI_COMPILE_TIME_MATH_H__