Applied reviewed header(DateTime to Uuid)
[platform/framework/native/appfw.git] / inc / FBaseUtilMath.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 /**
18  * @file                FBaseUtilMath.h
19  * @brief               This is the header file for the %Math class.
20  *
21  * This header file contains the declarations of the %Math class.
22  */
23 #ifndef _FBASE_UTIL_MATH_H_
24 #define _FBASE_UTIL_MATH_H_
25
26 #include <FBaseTypes.h>
27
28 namespace Tizen { namespace Base { namespace Utility
29 {
30 /**
31  * @class       Math
32  * @brief       This class is the wrapper class for the %Math Library.
33  *
34  * @since 2.0
35  *
36  * The %Math class provides various mathematical methods.
37  *
38  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/utility_namespace.htm">Utility</a>.
39  *
40  * The following example demonstrates how to use the %Math class.
41  *
42  * @code
43  *      #include <FBase.h>
44  *
45  *      using namespace Tizen::Base::Utility;
46  *
47  *      void
48  *      MyClass::MathSample(void)
49  *      {
50  *              double radius = 5.0;
51  *
52  *              double area = Math::GetPi() * Math::Pow(radius, 2.0L);
53  *      }
54  * @endcode
55  */
56
57 class _OSP_EXPORT_ Math
58 {
59 public:
60         /**
61          * Gets the absolute value of the specified integer.
62          *
63          * @since 2.0
64          *
65          * @return                      The absolute value of the specified integer
66          * @param[in]           x       An integer value
67          */
68         static int Abs(int x);
69
70         /**
71          * Gets the arc sine of the specified @c double integer. @n
72          * Returns a value between @c -PI/2 and @c PI/2.
73          *
74          * @since 2.0
75          *
76          * @return                      The arc sine of the input, @n
77          *                                      else Not-a-Number if @c x is out of the valid range
78          * @param[in]       x   A radian angle @n
79          *                                              It must be within the range @c -1 to @c 1 (inclusive).
80          * @see                         Acos()
81          * @see                         Atan()
82          */
83         static double Asin(double x);
84
85         /**
86          * Gets the arc cosine of the specified double integer. @n
87          * Returns a value between @c 0 and @c PI.
88          *
89          * @since 2.0
90          *
91          * @return                      The arc cosine of the input, @n
92          *                                      else Not-a-Number if @c x is out of the valid range
93          * @param[in]       x   A radian angle @n
94          *                                              It must be within the range @c -1 to @c 1 (inclusive).
95          * @see                         Asin()
96          * @see                         Atan()
97          */
98         static double Acos(double x);
99
100         /**
101          * Gets the arc tangent of the specified @c double integer. @n
102          * Returns a value between @c -PI/2 and @c PI/2.
103          *
104          * @since 2.0
105          *
106          * @return              The arc tangent of the input
107          * @param[in]   x       A radian angle
108          * @see                         Asin()
109          * @see             Acos()
110          */
111         static double Atan(double x);
112
113         /**
114          * Gets the smallest integer that is greater than or equal to the specified @c double integer. @n
115          * For example, if @c x is @c 3.9, Ceiling(double) returns @c 4.0. @n
116          * The returned value is an integer but the type is @c double.
117          *
118          * @since 2.0
119          *
120          * @return              The smallest integer that is greater than or equal to the input
121          * @param[in]   x               A floating point value
122          */
123         static double Ceiling(double x);
124
125         /**
126          * Gets the cosine of the specified @c double integer. @n
127          * Returns a value between @c -1 and @c 1.
128          *
129          * @since 2.0
130          *
131          * @return        The cosine of the input
132          * @param[in] x         A radian angle
133          * @see                         Sin()
134          * @see                         Tan()
135          */
136         static double Cos(double x);
137
138         /**
139          * Gets the hyperbolic cosine of the specified @c double integer.
140          *
141          * @since 2.0
142          *
143          * @return              The hyperbolic cosine of the input
144          * @param[in] x         A radian angle
145          */
146         static double Cosh(double x);
147
148         /**
149          * Gets the exponential value of the specified @c double integer.
150          *
151          * @since 2.0
152          *
153          * @return              The exponential value of the input
154          * @param[in]   x               A floating point value
155          */
156         static double Exp(double x);
157
158         /**
159          * Gets the largest integer that is less than or equal to the input. @n
160          * For example, if @c x is @c 3.3 then Floor(double) returns @c 3.0. @n
161          * The returned value is an integer but the type is @c double.
162          *
163          * @since 2.0
164          *
165          * @return              The largest @c double integer that is less than or equal to the input
166          * @param[in]   x               A floating point value
167          */
168         static double Floor(double x);
169
170         /**
171          * Gets the natural logarithm of the specified number.
172          *
173          * @since 2.0
174          *
175          * @return              The natural logarithm of the input
176          * @param[in]   x       A floating point value
177          */
178         static double Log(double x);
179
180         /**
181          * Gets the logarithm to the base 10 of the specified number.
182          *
183          * @since 2.0
184          *
185          * @return              The logarithm to the base 10 of the input
186          * @param[in]   x       A floating point value
187          */
188         static double Log10(double x);
189
190         /**
191          * Gets the greater of the two specified integer values. @n
192          * If both inputs have the same value, this method returns the same value.
193          *
194          * @since 2.0
195          *
196          * @return              The greater of the two integer values
197          * @param[in]   x               An integer value
198          * @param[in]   y               An integer value
199          * @see                         Min()
200          */
201         static int Max(int x, int y);
202
203         /**
204          * Gets the greater of the two floating point values. @n
205          * If both inputs have the same value, this method returns the same value. @n
206          * If either value is not a valid number, then this method returns Not-a-Number.
207          *
208          * @since 2.0
209          *
210          * @return              The greater of the two floating point values
211          * @param[in]   x               A floating point value
212          * @param[in]   y               A floating point value
213          * @see                 Min()
214          */
215         static double Max(double x, double y);
216
217         /**
218          * Gets the smaller of the two integer values. @n
219          * If both inputs have the same value, this method returns the same value.
220          *
221          * @since 2.0
222          *
223          * @return              The smaller of the two integer values
224          * @param[in]   x               An integer value
225          * @param[in]   y               An integer value
226          * @see                         Max()
227          */
228         static int Min(int x, int y);
229
230         /**
231          * Gets the smaller of the two @c double values. @n
232          * If both inputs have the same value, this method returns the same value. @n
233          * If either value is not a valid number, this method returns Not-a-Number.
234          *
235          * @since 2.0
236          *
237          * @return              The smaller of the two @c double values
238          * @param[in]   x               A floating point value
239          * @param[in]   y               A floating point value
240          * @see                         Max()
241          */
242         static double Min(double x, double y);
243
244         /**
245          * Gets the value of @c x raised to the power of @c y.
246          *
247          * @since 2.0
248          *
249          * @return              @c x raised to the power of @c y, @n
250          *                              else Not-a-Number if @c x and @c y do not satisfy the conditions described below
251          * @param[in]   x       A floating point value
252          * @param[in]   y       A floating point value
253          * @remarks
254          *                              - @li @c x cannot be negative if @c y is a fractional value.
255          *                              - @li @c x cannot be @c 0 if @c y is less than or equal to @c 0.
256          */
257         static double Pow(double x, double y);
258
259         /**
260          * Gets the nearest integer to the specified number.
261          *
262          * @since 2.0
263          *
264          * @return              The closest integer to the specified input
265          * @param[in]   x               A floating point value
266          */
267         static double Round(double x);
268
269         /**
270          * Gets the sine of the specified @c double integer. @n
271          * Returns a value between @c -1 and @c 1.
272          *
273          * @since 2.0
274          *
275          * @return              The sine of the input
276          * @param[in]   x               A radian angle
277          * @see                         Cos()
278          * @see                         Tan()
279          */
280         static double Sin(double x);
281
282         /**
283          * Gets the hyperbolic sine of the specified @c double integer.
284          *
285          * @since 2.0
286          *
287          * @return              The hyperbolic sine of the input
288          * @param[in]   x               A radian angle
289          */
290         static double Sinh(double x);
291
292         /**
293          * Gets the square root of the specified number.
294          *
295          * @since 2.0
296          *
297          * @return              The square root of the input, @n
298          *                              else Not-a-Number if @c x is a negative number
299          * @param[in]   x               A non-negative floating point value
300          */
301         static double Sqrt(double x);
302
303         /**
304          * Gets the tangent of the specified @c double integer.
305          *
306          * @since 2.0
307          *
308          * @return              The tangent of the input
309          * @param[in]   x               A radian angle
310          * @see                         Sin()
311          * @see             Cos()
312          */
313         static double Tan(double x);
314
315         /**
316         * Gets the hyperbolic tangent of the specified @c double integer.
317          *
318          * @since 2.0
319          *
320          * @return              The hyperbolic tangent of the input
321          * @param[in]   x               A radian angle
322          */
323         static double Tanh(double x);
324
325
326         /**
327          * Initializes a random number generator.
328          *
329          * @since 2.0
330          *
331          * @param[in]   seed    The integer value used as a seed by the pseudo-random number generator algorithm
332          * @see                         Rand()
333          */
334         static void Srand(unsigned int seed);
335
336
337         /**
338          * Gets a random integral number in the range @c 0 to @c RAND_VALUE_MAX.
339          *
340          * @since 2.0
341          *
342          * @return              The integer value between @c 0 and @c RAND_VALUE_MAX
343          * @remarks             This method uses a seed to generate the pseudo-random numbers, that must be initialized to some distinctive value using Srand().
344          * @see                         Srand()
345          */
346         static int Rand(void);
347
348         /**
349          * Gets the constant value of E (the base of natural logarithms).
350          *
351          * @since 2.0
352          *
353          * @return                      The constant value of E
354          */
355         static const double GetE(void);
356
357         /**
358          * Gets the constant value of PI.
359          *
360          * @since 2.0
361          *
362          * @return                      The constant value of PI
363          */
364         static const double GetPi(void);
365
366         /**
367          * The maximum value that can be returned by the Rand() method.
368          *
369          * @since 2.0
370          */
371         static const int RAND_VALUE_MAX = 32767;  // 0x7fff
372
373
374 private:
375         /**
376          * This default constructor is intentionally declared as private because this class cannot be constructed.
377          */
378         Math(void);
379
380         /**
381          * This destructor is intentionally declared as private because this class cannot be constructed.
382          */
383         virtual ~Math(void);
384
385         /**
386          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
387          *
388          * @param[in]   rhs     The instance of the Math
389          */
390         Math(const Math& rhs);
391
392         /**
393          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
394          *
395          * @param[in]   rhs     An instance of %Math
396          */
397         Math& operator =(const Math& rhs);
398 }; // Math
399
400 }}} // Tizen::Base::Utility
401
402 #endif // _FBASE_UTIL_MATH_H_