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
25namespace Ti {
26
27
28
29
30// default float point type
31typedef float real;
32
33
34
35
36template <typename T>
37int floor(T x);
38
39template <typename T>
40int round(T x);
41
42template <typename T>
43const T & min(const T & a, const T & b);
44
45template <typename T>
46const T & max(const T & a, const T & b);
47
48template <typename T>
49const T & bound(const T & min, const T & x, const T & max);
50
51template <typename T>
52T abs(const T & x);
53
54
55
56
57template <typename T>
58inline int floor(const T x) {
59    return static_cast<int>(x);
60}
61
62template <typename T>
63inline 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
71template <typename T>
72inline const T & min(const T & a, const T & b) {
73    return a < b ? a : b;
74}
75
76template <typename T>
77inline const T & max(const T & a, const T & b) {
78    return a < b ? b : a;
79}
80
81template <typename T>
82inline const T & bound(const T & min, const T & x, const T & max) {
83    return x < min ? min : x > max ? max : x;
84}
85
86template <typename T>
87inline 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