summaryrefslogtreecommitdiffstats
path: root/libtiutils/UtilsCommon.h
blob: 8aaeee7403ab6727b82df888fbf3106d8239a504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) Texas Instruments - http://www.ti.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TI_UTILS_COMMON_H
#define TI_UTILS_COMMON_H

#include <android/api-level.h>
#include <android/log.h>



namespace Ti {




// default float point type
typedef float real;




template <typename T>
int floor(T x);

template <typename T>
int round(T x);

template <typename T>
const T & min(const T & a, const T & b);

template <typename T>
const T & max(const T & a, const T & b);

template <typename T>
const T & bound(const T & min, const T & x, const T & max);

template <typename T>
T abs(const T & x);




template <typename T>
inline int floor(const T x) {
    return static_cast<int>(x);
}

template <typename T>
inline int round(const T x) {
    if ( x >= 0 ) {
        return floor(x + T(0.5));
    } else {
        return floor(x - floor(x - T(1)) + T(0.5)) + floor(x - T(1));
    }
}

template <typename T>
inline const T & min(const T & a, const T & b) {
    return a < b ? a : b;
}

template <typename T>
inline const T & max(const T & a, const T & b) {
    return a < b ? b : a;
}

template <typename T>
inline const T & bound(const T & min, const T & x, const T & max) {
    return x < min ? min : x > max ? max : x;
}

template <typename T>
inline T abs(const T & x) {
    return x >= 0 ? x : -x;
}




} // namespace Ti




#endif // TI_UTILS_COMMON_H