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 Flora License, Version 1.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://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_FRAMEWORK
29 #include <dali/public-api/common/dali-common.h>
31 namespace Dali DALI_IMPORT_API
34 * Compile time template to calculate base to the power of N
35 * Note! values need to be compile time constants
36 * Usage: <code>Power< 10, 2 >::value; // value=100</code>
37 * @param mantissa to raise to exponent
38 * @param N exponent to use for mantissa
40 template< size_t mantissa, size_t exponent >
43 enum { value = mantissa * Power< mantissa, exponent - 1 >::value };
47 * Compile time template to calculate base to the power of N
48 * Specialisation for power of 1
49 * @param mantissa to raise to exponent
51 template< size_t mantissa >
52 struct Power< mantissa, 1 >
54 enum { value = mantissa };
58 * Compile time template to calculate base to the power of N
59 * Specialisation for power of 0
60 * @param mantissa to raise to exponent
62 template< size_t mantissa >
63 struct Power< mantissa, 0 >
69 * 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 * Compile time template to calculate base logarithm of N
83 * Specialisation for logarithm of 1
84 * @param base logarithm to calculate
86 template< size_t base >
93 * Compile time template to calculate base logarithm of N
94 * Specialisation for logarithm of 0
95 * @param base logarithm to calculate
97 template< size_t base >
105 * Compile time template to calculate the machine epsilon for a given floating point number
106 * Note! value needs to be compile time constant
107 * Usage: <code>Epsilon<1000>::value; value equals 0.000119209</code>
108 * @param N the number for which to calculate the machine epsilon
113 // take log10 of the number to get to the nearest power of 10 number and divide that by 10
114 // template recursion will take care of the rest
116 static constexpr float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
118 static const float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
123 * Compile time template to calculate the machine epsilon for a given floating point number
124 * Specialisation for epsilon of 1
125 * predefined value calculated on ARM Cortex A9 target
131 static constexpr float value = 1.19209e-07f;
133 static const float value = 1.19209e-07f;
138 * Compile time template to calculate the machine epsilon for a given floating point number
139 * Specialisation for epsilon of 0
140 * predefined value calculated on ARM Cortex A9 target
146 static constexpr float value = 1.4013e-45f;
148 static const float value = 1.4013e-45f;
157 #endif // __DALI_COMPILE_TIME_MATH_H__