2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief Header file for internal float math functions
22 * This file contains declarations internal float math functions.
26 #ifndef _FUI_INTERNAL_MATH_H_
27 #define _FUI_INTERNAL_MATH_H_
32 namespace Tizen { namespace Ui
37 _Abs(const T& t) { return t >= 0 ? t : -t;}
41 _Min(const T& a, const T& b)
50 _Max(const T& a, const T& b)
57 #define ALMOST_ZERO_FLOAT 0.00001f
58 #define ALMOST_ZERO_DOUBLE 0.000000000001
60 // We do not use epsilon but hard-coded value to check if the two values are close "*ENOUGH*".
62 _FloatCompare(double p1, double p2)
64 return (p1 == p2 || _Abs(p1 - p2) <= ALMOST_ZERO_DOUBLE * _Min(_Abs(p1), _Abs(p2)));
68 _FloatCompare(float p1, float p2)
70 return (p1 == p2 || _Abs(p1 - p2) <= ALMOST_ZERO_FLOAT * _Min(_Abs(p1), _Abs(p2)));
74 _FloatCompareGE(float p1, float p2)
76 return (p1 >= p2 || _Abs(p1 - p2) <= ALMOST_ZERO_FLOAT * _Min(_Abs(p1), _Abs(p2)));
80 _FloatCompareGE(double p1, double p2)
82 return (p1 >= p2 || _Abs(p1 - p2) <= ALMOST_ZERO_DOUBLE * _Min(_Abs(p1), _Abs(p2)));
86 _FloatCompareLE(float p1, float p2)
88 return (p1 <= p2 || _Abs(p1 - p2) <= ALMOST_ZERO_FLOAT * _Min(_Abs(p1), _Abs(p2)));
92 _FloatCompareLE(double p1, double p2)
94 return (p1 <= p2 || _Abs(p1 - p2) <= ALMOST_ZERO_DOUBLE * _Min(_Abs(p1), _Abs(p2)));
98 _FloatHardCompare(double p1, double p2)
100 return (_Abs(p1 - p2) <= DBL_EPSILON);
104 _FloatHardCompare(float p1, float p2)
106 return (_Abs(p1 - p2) <= FLT_EPSILON);
111 #endif // _FUI_INTERNAL_MATH_H_