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.
22 * @addtogroup CAPI_DALI_MATH_MODULE
30 #include <dali/public-api/common/dali-common.h>
32 namespace Dali DALI_IMPORT_API
35 * @brief Compile time template to calculate base to the power of N.
37 * Note! values need to be compile time constants
38 * Usage: <code>Power< 10, 2 >::value; // value=100</code>
39 * @param mantissa to raise to exponent
40 * @param N exponent to use for mantissa
42 template< size_t mantissa, size_t exponent >
45 enum { value = mantissa * Power< mantissa, exponent - 1 >::value };
49 * @brief Compile time template to calculate base to the power of N.
51 * Specialisation for power of 1
52 * @param mantissa to raise to exponent
54 template< size_t mantissa >
55 struct Power< mantissa, 1 >
57 enum { value = mantissa };
61 * @brief Compile time template to calculate base to the power of N.
63 * Specialisation for power of 0
64 * @param mantissa to raise to exponent
66 template< size_t mantissa >
67 struct Power< mantissa, 0 >
73 * @brief Compile time template to calculate base logarithm of N.
75 * Note! values need to be compile time constants
76 * Usage: <code>Log< 100, 10 >::value; value equals 2</code>
77 * @param number for which to calculate the logarithm
78 * @param base logarithm to calculate
80 template< size_t number, size_t base = 2 >
83 enum { value = 1 + Log< number / base, base >::value };
87 * @brief Compile time template to calculate base logarithm of N.
89 * Specialisation for logarithm of 1
90 * @param base logarithm to calculate
92 template< size_t base >
99 * @brief Compile time template to calculate base logarithm of N.
101 * Specialisation for logarithm of 0
102 * @param base logarithm to calculate
104 template< size_t base >
105 struct Log< 0, base >
112 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
114 * Note! value needs to be compile time constant
115 * Usage: <code>Epsilon<1000>::value; value equals 0.000119209</code>
116 * @param N the number for which to calculate the machine epsilon
121 // take log10 of the number to get to the nearest power of 10 number and divide that by 10
122 // template recursion will take care of the rest
124 static constexpr float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
126 static const float value = 10.0f * Epsilon< Power< 10, Log< N, 10 >::value >::value / 10 >::value;
131 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
133 * Specialisation for epsilon of 1
134 * predefined value calculated on ARM Cortex A9 target
140 static constexpr float value = 1.19209e-07f;
142 static const float value = 1.19209e-07f;
147 * @brief Compile time template to calculate the machine epsilon for a given floating point number.
149 * Specialisation for epsilon of 0
150 * predefined value calculated on ARM Cortex A9 target
156 static constexpr float value = 1.4013e-45f;
158 static const float value = 1.4013e-45f;
167 #endif // __DALI_COMPILE_TIME_MATH_H__