• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) Texas Instruments - http://www.ti.com/
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 #ifndef TI_UTILS_COMMON_H
18 #define TI_UTILS_COMMON_H
19 
20 #include <android/api-level.h>
21 #include <android/log.h>
22 
23 
24 
25 namespace Ti {
26 
27 
28 
29 
30 // default float point type
31 typedef float real;
32 
33 
34 
35 
36 template <typename T>
37 int floor(T x);
38 
39 template <typename T>
40 int round(T x);
41 
42 template <typename T>
43 const T & min(const T & a, const T & b);
44 
45 template <typename T>
46 const T & max(const T & a, const T & b);
47 
48 template <typename T>
49 const T & bound(const T & min, const T & x, const T & max);
50 
51 template <typename T>
52 T abs(const T & x);
53 
54 
55 
56 
57 template <typename T>
floor(const T x)58 inline int floor(const T x) {
59     return static_cast<int>(x);
60 }
61 
62 template <typename T>
round(const T x)63 inline int round(const T x) {
64     if ( x >= 0 ) {
65         return floor(x + T(0.5));
66     } else {
67         return floor(x - floor(x - T(1)) + T(0.5)) + floor(x - T(1));
68     }
69 }
70 
71 template <typename T>
min(const T & a,const T & b)72 inline const T & min(const T & a, const T & b) {
73     return a < b ? a : b;
74 }
75 
76 template <typename T>
max(const T & a,const T & b)77 inline const T & max(const T & a, const T & b) {
78     return a < b ? b : a;
79 }
80 
81 template <typename T>
bound(const T & min,const T & x,const T & max)82 inline const T & bound(const T & min, const T & x, const T & max) {
83     return x < min ? min : x > max ? max : x;
84 }
85 
86 template <typename T>
abs(const T & x)87 inline T abs(const T & x) {
88     return x >= 0 ? x : -x;
89 }
90 
91 
92 
93 
94 } // namespace Ti
95 
96 
97 
98 
99 #endif // TI_UTILS_COMMON_H
100