FastUIDraw
math.hpp
Go to the documentation of this file.
1 /*!
2  * \file math.hpp
3  * \brief file math.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 
20 #ifndef FASTUIDRAW_MATH_HPP
21 #define FASTUIDRAW_MATH_HPP
22 
23 #include <math.h>
24 #include <stdlib.h>
25 
26 namespace fastuidraw
27 {
28 /*!\addtogroup Utility
29  * @{
30  */
31 
32 /*!\def FASTUIDRAW_PI
33  * Macro giving the value of pi as a float
34  */
35 #define FASTUIDRAW_PI 3.14159265358979323846f
36 
37  /*!
38  * Conveniance overload avoiding to rely on std::
39  */
40  template<typename T>
41  inline
42  const T&
43  t_min(const T &a, const T &b)
44  {
45  return (a < b) ? a : b;
46  }
47 
48  /*!
49  * Conveniance overload avoiding to rely on std::
50  */
51  template<typename T>
52  inline
53  const T&
54  t_max(const T &a, const T &b)
55  {
56  return (a < b) ? b : a;
57  }
58 
59  /*!
60  * Return the sign of a value.
61  */
62  template<typename T>
63  inline
64  T
65  t_sign(const T &a)
66  {
67  return (a < T(0)) ? T(-1) : T(1);
68  }
69 
70  /*!
71  * Conveniance overload avoiding to rely on std::
72  */
73  inline
74  float
75  t_sin(float x) { return ::sinf(x); }
76 
77  /*!
78  * Conveniance overload avoiding to rely on std::
79  */
80  inline
81  float
82  t_cos(float x) { return ::cosf(x); }
83 
84  /*!
85  * Conveniance overload avoiding to rely on std::
86  */
87  inline
88  float
89  t_tan(float x) { return ::tanf(x); }
90 
91  /*!
92  * Conveniance overload avoiding to rely on std::
93  */
94  inline
95  float
96  t_sqrt(float x) { return ::sqrtf(x); }
97 
98  /*!
99  * Conveniance overload avoiding to rely on std::
100  */
101  inline
102  float
103  t_asin(float x) { return ::asinf(x); }
104 
105  /*!
106  * Conveniance overload avoiding to rely on std::
107  */
108  inline
109  float
110  t_acos(float x) { return ::acosf(x); }
111 
112  /*!
113  * Conveniance overload avoiding to rely on std::
114  */
115  inline
116  float
117  t_atan(float x) { return ::atanf(x); }
118 
119  /*!
120  * Conveniance overload avoiding to rely on std::
121  */
122  inline
123  float
124  t_atan2(float y, float x) { return ::atan2f(y, x); }
125 
126  /*!
127  * Conveniance overload avoiding to rely on std::
128  */
129  inline
130  double
131  t_sin(double x) { return ::sin(x); }
132 
133  /*!
134  * Conveniance overload avoiding to rely on std::
135  */
136  inline
137  double
138  t_cos(double x) { return ::cos(x); }
139 
140  /*!
141  * Conveniance overload avoiding to rely on std::
142  */
143  inline
144  double
145  t_tan(double x) { return ::tan(x); }
146 
147  /*!
148  * Conveniance overload avoiding to rely on std::
149  */
150  inline
151  double
152  t_sqrt(double x) { return ::sqrt(x); }
153 
154  /*!
155  * Conveniance overload avoiding to rely on std::
156  */
157  inline
158  double
159  t_asin(double x) { return ::asin(x); }
160 
161  /*!
162  * Conveniance overload avoiding to rely on std::
163  */
164  inline
165  double
166  t_acos(double x) { return ::acos(x); }
167 
168  /*!
169  * Conveniance overload avoiding to rely on std::
170  */
171  inline
172  double
173  t_atan(double x) { return ::atan(x); }
174 
175  /*!
176  * Conveniance overload avoiding to rely on std::
177  */
178  inline
179  double
180  t_atan2(double y, double x) { return ::atan2(y, x); }
181 
182  /*!
183  * Conveniance overload avoiding to rely on std::
184  */
185  inline
186  long double
187  t_sin(long double x) { return ::sinl(x); }
188 
189  /*!
190  * Conveniance overload avoiding to rely on std::
191  */
192  inline
193  long double
194  t_cos(long double x) { return ::cosl(x); }
195 
196  /*!
197  * Conveniance overload avoiding to rely on std::
198  */
199  inline
200  long double
201  t_tan(long double x) { return ::tanl(x); }
202 
203  /*!
204  * Conveniance overload avoiding to rely on std::
205  */
206  inline
207  long double
208  t_sqrt(long double x) { return ::sqrtl(x); }
209 
210  /*!
211  * Conveniance overload avoiding to rely on std::
212  */
213  inline
214  long double
215  t_asin(long double x) { return ::asinl(x); }
216 
217  /*!
218  * Conveniance overload avoiding to rely on std::
219  */
220  inline
221  long double
222  t_acos(long double x) { return ::acosl(x); }
223 
224  /*!
225  * Conveniance overload avoiding to rely on std::
226  */
227  inline
228  long double
229  t_atan(long double x) { return ::atanl(x); }
230 
231  /*!
232  * Conveniance overload avoiding to rely on std::
233  */
234  inline
235  long double
236  t_atan2(long double y, long double x) { return ::atan2l(y, x); }
237 
238  /*!
239  * Conveniance overload avoiding to rely on std::
240  */
241  inline
242  int
243  t_abs(int x) { return ::abs(x); }
244 
245  /*!
246  * Conveniance overload avoiding to rely on std::
247  */
248  inline
249  long
250  t_abs(long x) { return ::labs(x); }
251 
252  /*!
253  * Conveniance overload avoiding to rely on std::
254  */
255  inline
256  long long
257  t_abs(long long x) { return ::llabs(x); }
258 
259  /*!
260  * Conveniance overload avoiding to rely on std::
261  */
262  inline
263  float
264  t_abs(float x) { return fabsf(x); }
265 
266  /*!
267  * Conveniance overload avoiding to rely on std::
268  */
269  inline
270  double
271  t_abs(double x) { return fabs(x); }
272 
273  /*!
274  * Conveniance overload avoiding to rely on std::
275  */
276  inline
277  long double
278  t_abs(long double x) { return fabsl(x); }
279 
280 /*! @} */
281 }
282 
283 #endif
float t_asin(float x)
Definition: math.hpp:103
float t_atan2(float y, float x)
Definition: math.hpp:124
float t_cos(float x)
Definition: math.hpp:82
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
float t_atan(float x)
Definition: math.hpp:117
float t_acos(float x)
Definition: math.hpp:110
const T & t_max(const T &a, const T &b)
Definition: math.hpp:54
float t_sin(float x)
Definition: math.hpp:75
const T & t_min(const T &a, const T &b)
Definition: math.hpp:43
float t_sqrt(float x)
Definition: math.hpp:96
float t_tan(float x)
Definition: math.hpp:89
T t_sign(const T &a)
Definition: math.hpp:65
int t_abs(int x)
Definition: math.hpp:243