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_MATH_MODULE
29 #include <dali/public-api/common/dali-common.h>
31 namespace Dali DALI_IMPORT_API
34 * @brief Compile time template to calculate base to the power of N.
36 * Note! values need to be compile time constants
37 * Usage: <code>Power< 10, 2 >::value; // value=100</code>
38 * @param mantissa to raise to exponent
39 * @param N exponent to use for mantissa
41 template< size_t mantissa, size_t exponent >
44 enum { value = mantissa * Power< mantissa, exponent - 1 >::value };
48 * @brief Compile time template to calculate base to the power of N.
50 * Specialisation for power of 1
51 * @param mantissa to raise to exponent
53 template< size_t mantissa >
54 struct Power< mantissa, 1 >
56 enum { value = mantissa };
60 * @brief Compile time template to calculate base to the power of N.
62 * Specialisation for power of 0
63 * @param mantissa to raise to exponent
65 template< size_t mantissa >
66 struct Power< mantissa, 0 >
72 * @brief Compile time template to calculate base logarithm of N.
74 * Note! values need to be compile time constants
75 * Usage: <code>Log< 100, 10 >::value; value equals 2</code>
76 * @param number for which to calculate the logarithm
77 * @param base logarithm to calculate
79 template< size_t number, size_t base = 2 >
82 enum { value = 1 + Log< number / base, base >::value };
86 * @brief Compile time template to calculate base logarithm of N.
88 * Specialisation for logarithm of 1
89 * @param base logarithm to calculate
91 template< size_t base >
98 * @brief Compile time template to calculate base logarithm of N.
100 * Specialisation for logarithm of 0
101 * @param base logarithm to calculate
103 template< size_t base >
104 struct Log< 0, base >
111 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
113 * Note! value needs to be compile time constant
114 * Usage: <code>Epsilon<1000>::value; value equals 0.000119209</code>
115 * @param N the number for which to calculate the machine epsilon
120 // take log10 of the number to get to the nearest power of 10 number and divide that by 10
121 // template recursion will take care of the rest
123 static constexpr float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
125 static const float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
130 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
132 * Specialisation for epsilon of 1
133 * predefined value calculated on ARM Cortex A9 target
139 static constexpr float value = 1.19209e-07f;
141 static const float value = 1.19209e-07f;
146 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
148 * Specialisation for epsilon of 0
149 * predefined value calculated on ARM Cortex A9 target
155 static constexpr float value = 1.4013e-45f;
157 static const float value = 1.4013e-45f;
166 #endif // __DALI_COMPILE_TIME_MATH_H__