/* * 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 #include namespace Ti { // default float point type typedef float real; template int floor(T x); template int round(T x); template const T & min(const T & a, const T & b); template const T & max(const T & a, const T & b); template const T & bound(const T & min, const T & x, const T & max); template T abs(const T & x); template inline int floor(const T x) { return static_cast(x); } template 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 inline const T & min(const T & a, const T & b) { return a < b ? a : b; } template inline const T & max(const T & a, const T & b) { return a < b ? b : a; } template inline const T & bound(const T & min, const T & x, const T & max) { return x < min ? min : x > max ? max : x; } template inline T abs(const T & x) { return x >= 0 ? x : -x; } } // namespace Ti #endif // TI_UTILS_COMMON_H