sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FBaseUtilMath.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FBaseUtilMath.h
20  * @brief               This is the header file for the %Math class.
21  *
22  * This header file contains the declarations of the %Math class.
23  */
24 #ifndef _FBASE_UTIL_MATH_H_
25 #define _FBASE_UTIL_MATH_H_
26
27 #include <FBaseTypes.h>
28
29 namespace Tizen { namespace Base { namespace Utility
30 {
31 /**
32  * @class       Math
33  * @brief       This class is the wrapper class for %Math Library.
34  *
35  * @since 2.0
36  *
37  * The %Math class provides various mathematical methods.
38  *
39  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/utility_namespace.htm">Utility</a>.
40  *
41  * The following example demonstrates how to use the %Math class.
42  *
43  * @code
44  *      #include <FBase.h>
45  *
46  *      using namespace Tizen::Base::Utility;
47  *
48  *      void
49  *      MyClass::MathSample(void)
50  *      {
51  *              double radius = 5.0;
52  *
53  *              double area = Math::GetPi() * Math::Pow(radius, 2.0L);
54  *      }
55  * @endcode
56  */
57
58 class _OSP_EXPORT_ Math
59 {
60 public:
61         /**
62          * Gets the absolute value of the specified integer.
63          *
64          * @since 2.0
65          *
66          * @return                      The absolute value of the specified integer
67          * @param[in]           x       An integer value
68          */
69         static int Abs(int x);
70
71         /**
72         * Gets the arc sine of the specified @c double integer. @n
73          * Returns a value between @c -PI/2 and @c PI/2.
74          *
75          * @since 2.0
76          *
77          * @return                      The arc sine of the input, @n
78          *                                      else Not-a-Number if @c x is out of range
79          * @param[in]       x   A radian angle @n
80          *                                      It must be within the range @c -1 to @c 1 (inclusive).
81          * @see                         Acos()
82          * @see                         Atan()
83          */
84         static double Asin(double x);
85
86         /**
87         * Gets the arc cosine of the specified double integer. @n
88          * Returns a value between @c 0 and @c PI.
89          *
90          * @since 2.0
91          *
92          * @return                      The arc cosine of the input, @n
93          *                                      else Not-a-Number if @c x is out of range
94          * @param[in]       x   A radian angle @n
95          *                                      It must be within the range @c -1 to @c 1 (inclusive).
96          * @see                         Asin()
97          * @see                         Atan()
98          */
99         static double Acos(double x);
100
101         /**
102         * Gets the arc tangent of the specified @c double integer. @n
103          * Returns a value between @c -PI/2 and @c PI/2.
104          *
105          * @since 2.0
106          *
107          * @return              The arc tangent of the input
108          * @param[in] x         A radian angle
109          * @see                         Asin()
110          * @see             Acos()
111          */
112         static double Atan(double x);
113
114         /**
115          * Gets the smallest integer that is greater than or equal to the specified @c double integer. @n
116          * For example, if @c x is @c 3.9, Ceiling(double) returns @c 4.0. @n
117          * The returned value is an integer but the type is @c double.
118          *
119          * @since 2.0
120          *
121          * @return              The smallest integer that is greater than or equal to the input
122          * @param[in] x         A floating point value
123          */
124         static double Ceiling(double x);
125
126         /**
127         * Gets the cosine of the specified @c double integer. @n
128          * Returns a value between @c -1 and @c 1.
129          *
130          * @since 2.0
131          *
132          * @return              The cosine of the input
133          * @param[in] x         A radian angle
134          * @see                         Sin()
135          * @see                         Tan()
136          */
137         static double Cos(double x);
138
139         /**
140         * Gets the hyperbolic cosine of the specified @c double integer.
141          *
142          * @since 2.0
143          *
144          * @return              The hyperbolic cosine of the input
145          * @param[in] x         A radian angle
146          */
147         static double Cosh(double x);
148
149         /**
150         * Gets the exponential value of the specified @c double integer.
151          *
152          * @since 2.0
153          *
154          * @return              The exponential value of the input
155          * @param[in] x         A floating point value
156          */
157         static double Exp(double x);
158
159         /**
160          * Gets the largest integer that is less than or equal to the input. @n
161          * For example, if @c x is @c 3.3 then Floor(double) returns @c 3.0. @n
162          * The returned value is an integer but the type is @c double.
163          *
164          * @since 2.0
165          *
166          * @return              The largest @c double integer that is less than or equal to the input
167          * @param[in] x         A floating point value
168          */
169         static double Floor(double x);
170
171         /**
172          * Gets the natural logarithm of the specified number.
173          *
174          * @since 2.0
175          *
176          * @return              The natural logarithm of the input
177          * @param[in] x A floating point value
178          */
179         static double Log(double x);
180
181         /**
182          * Gets the logarithm to the base 10 of the specified number.
183          *
184          * @since 2.0
185          *
186          * @return              The logarithm to the base 10 of the input
187          * @param[in] x A floating point value
188          */
189         static double Log10(double x);
190
191         /**
192          * Gets the greater of the two specified integer values. @n
193          * If both inputs have the same value, this method returns the same value.
194          *
195          * @since 2.0
196          *
197          * @return              The greater of the two integer values
198          * @param[in] x         An integer value
199          * @param[in] y         An integer value
200          * @see                         Min()
201          */
202         static int Max(int x, int y);
203
204         /**
205          * Gets the greater of the two floating point values. @n
206          * If both inputs have the same value, this method returns the same value. @n
207          * If either value is not a valid number, then this method returns Not-a-Number.
208          *
209          * @since 2.0
210          *
211          * @return              The greater of the two floating point values
212          * @param[in] x         A floating point value
213          * @param[in] y         A floating point value
214          * @see                         Min()
215          */
216         static double Max(double x, double y);
217
218         /**
219          * Gets the smaller of the two integer values. @n
220          * If both inputs have the same value, this method returns the same value.
221          *
222          * @since 2.0
223          *
224          * @return              The smaller of the two integer values
225          * @param[in] x         An integer value
226          * @param[in] y         An integer value
227          * @see                         Max()
228          */
229         static int Min(int x, int y);
230
231         /**
232          * Gets the smaller of the two @c double values. @n
233          * If both inputs have the same value, this method returns the same value. @n
234          * If either value is not a valid number, this method returns Not-a-Number.
235          *
236          * @since 2.0
237          *
238          * @return              The smaller of the two @c double values
239          * @param[in] x         A floating point value
240          * @param[in] y         A floating point value
241          * @see                         Max()
242          */
243         static double Min(double x, double y);
244
245         /**
246          * Gets the value of @c x raised to the power of @c y.
247          *
248          * @since 2.0
249          *
250          * @return              @c x raised to the power of @c y, @n
251          *                                      else Not-a-Number if @c x and @c y do not satisfy the conditions described below
252          * @param[in] x A floating point value
253          * @param[in] y A floating point value
254          * @remarks             @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    An integer value to use as 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              An 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_