Update copyright year to 2015 for public api: core
[platform/core/uifw/dali-core.git] / dali / public-api / math / compile-time-math.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/math/compile-time-math.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/compile-time-assert.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29   // verification for static asserts, these get removed from final binary by the linker
30   const unsigned int value0 = Power<10,0>::value;
31   DALI_COMPILE_TIME_ASSERT( value0 == 1 ); // cannot have template with , inside macro... macros suck
32   const unsigned int value1 = Power<10,1>::value;
33   DALI_COMPILE_TIME_ASSERT( value1 == 10 );
34   const unsigned int value2 = Power<10,2>::value;
35   DALI_COMPILE_TIME_ASSERT( value2 == 100 );
36   const unsigned int value3 = Power<10,3>::value;
37   DALI_COMPILE_TIME_ASSERT( value3 == 1000 );
38   const unsigned int value4 = Power<4,4>::value;
39   DALI_COMPILE_TIME_ASSERT( value4 == 256 );
40
41   const unsigned int log0 = Log<0, 10>::value;
42   DALI_COMPILE_TIME_ASSERT( log0 == 0 );
43   const unsigned int log1 = Log<1, 10>::value;
44   DALI_COMPILE_TIME_ASSERT( log1 == 0 );
45   const unsigned int log2 = Log<2, 10>::value;
46   DALI_COMPILE_TIME_ASSERT( log2 == 1 );
47   const unsigned int log3 = Log<10, 10>::value;
48   DALI_COMPILE_TIME_ASSERT( log3 == 1 );
49   const unsigned int log4 = Log<100, 10>::value;
50   DALI_COMPILE_TIME_ASSERT( log4 == 2 );
51   const unsigned int log5 = Log<1000, 10>::value;
52   DALI_COMPILE_TIME_ASSERT( log5 == 3 );
53
54   const unsigned int logpow0 = Log<Power<10,0>::value, 10 >::value;
55   DALI_COMPILE_TIME_ASSERT( logpow0 == 0 );
56   const unsigned int logpow1 = Log<Power<2,0>::value, 2 >::value;
57   DALI_COMPILE_TIME_ASSERT( logpow1 == 0 );
58   const unsigned int logpow2 = Log<Power<10,2>::value, 10 >::value;
59   DALI_COMPILE_TIME_ASSERT( logpow2 == 2 );
60   const unsigned int logpow3 = Log<Power<2,2>::value, 2 >::value;
61   DALI_COMPILE_TIME_ASSERT( logpow3 == 2 );
62
63   const unsigned int powlog0 = Power<10, Log<10,10>::value >::value;
64   DALI_COMPILE_TIME_ASSERT( powlog0 == 10 );
65   const unsigned int powlog1 = Power<10, Log<100,10>::value >::value;
66   DALI_COMPILE_TIME_ASSERT( powlog1 == 100 );
67
68   // TODO unfortunately cannot static assert floats so cannot test EPSILON here...
69
70 } // namespace
71
72 } // namespace Dali