1 #ifndef __DALI_COMPILE_TIME_MATH_H__
2 #define __DALI_COMPILE_TIME_MATH_H__
5 * Copyright (c) 2014 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>
27 namespace Dali DALI_IMPORT_API
30 * @brief Compile time template to calculate base to the power of N.
32 * Note! values need to be compile time constants
33 * Usage: <code>Power< 10, 2 >::value; // value=100</code>
34 * @param mantissa to raise to exponent
35 * @param N exponent to use for mantissa
37 template< size_t mantissa, size_t exponent >
40 enum { value = mantissa * Power< mantissa, exponent - 1 >::value };
44 * @brief Compile time template to calculate base to the power of N.
46 * Specialisation for power of 1
47 * @param mantissa to raise to exponent
49 template< size_t mantissa >
50 struct Power< mantissa, 1 >
52 enum { value = mantissa };
56 * @brief Compile time template to calculate base to the power of N.
58 * Specialisation for power of 0
59 * @param mantissa to raise to exponent
61 template< size_t mantissa >
62 struct Power< mantissa, 0 >
68 * @brief Compile time template to calculate base logarithm of N.
70 * Note! values need to be compile time constants
71 * Usage: <code>Log< 100, 10 >::value; value equals 2</code>
72 * @param number for which to calculate the logarithm
73 * @param base logarithm to calculate
75 template< size_t number, size_t base = 2 >
78 enum { value = 1 + Log< number / base, base >::value };
82 * @brief Compile time template to calculate base logarithm of N.
84 * Specialisation for logarithm of 1
85 * @param base logarithm to calculate
87 template< size_t base >
94 * @brief Compile time template to calculate base logarithm of N.
96 * Specialisation for logarithm of 0
97 * @param base logarithm to calculate
99 template< size_t base >
100 struct Log< 0, base >
107 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
109 * Note! value needs to be compile time constant
110 * Usage: <code>Epsilon<1000>::value; value equals 0.000119209</code>
111 * @param N the number for which to calculate the machine epsilon
116 // take log10 of the number to get to the nearest power of 10 number and divide that by 10
117 // template recursion will take care of the rest
119 static constexpr float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
121 static const float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
126 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
128 * Specialisation for epsilon of 1
129 * predefined value calculated on ARM Cortex A9 target
135 static constexpr float value = 1.19209e-07f;
137 static const float value = 1.19209e-07f;
142 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
144 * Specialisation for epsilon of 0
145 * predefined value calculated on ARM Cortex A9 target
151 static constexpr float value = 1.4013e-45f;
153 static const float value = 1.4013e-45f;
159 #endif // __DALI_COMPILE_TIME_MATH_H__