Merge "[devel_3.0_main] Cherry-pick Beautification of source-code. 80383" into devel_...
[platform/framework/native/appfw.git] / inc / FBaseDouble.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                FBaseDouble.h
19  * @brief               This is the header file for the %Double class.
20  *
21  * @see                 Tizen::Base::Number
22  *
23  * This header file contains the declarations of the %Double class.
24  */
25 #ifndef _FBASE_DOUBLE_H_
26 #define _FBASE_DOUBLE_H_
27
28 #include <FBaseNumber.h>
29
30
31 namespace Tizen { namespace Base
32 {
33 /**
34  *      @class  Double
35  *      @brief  This class is the wrapper class for the @c signed @c double built-in type.
36  *
37  *      @since 2.0
38  *
39  *  The %Double class is the wrapper class for the @c signed @c double built-in type.
40  *
41  *      It represents a double-precision 64-bit number with values ranging from negative
42  *      1.79769313486232e308 to positive 1.79769313486232e308. This class is useful when passing a @c double
43  *      value to a method expecting an instance of Object, such as Tizen::Base::Collection::Queue or
44  *      Tizen::Base::Collection::Stack. Furthermore, this class provides methods for converting
45  *      %Double (and @c double) to String, and String to %Double (and @c double).
46  *
47  *  The following example demonstrates how to use the %Double class.
48  *
49  *      @code
50  *
51  *      #include <FBase.h>
52  *
53  *      using namespace Tizen::Base;
54  *
55  *      // This method checks whether the given string object contains a string
56  *      // representation of the pre-defined minimum double value.
57  *      result
58  *      MyClass::Verify(const String& string, bool& out)
59  *      {
60  *              static const Double MINIMUM(1.23L);
61  *
62  *              result r = E_SUCCESS;
63  *
64  *              double d;
65  *              r = Double::Parse(string, d);
66  *              if (IsFailed(r))
67  *              {
68  *                      goto CATCH;
69  *              }
70  *
71  *              out = (MINIMUM.CompareTo(d) == 0) ? true: false;
72  *
73  *              return r;
74  *      CATCH:
75  *              return r;
76  *      }
77  *      @endcode
78  */
79 class _OSP_EXPORT_ Double
80         : public Number
81 {
82 public:
83         /**
84          * Initializes this instance of %Double with the specified value.
85          *
86          * @since 2.0
87          *
88          * @param[in]   value   A @c double value
89          */
90         Double(double value = 0.0L);
91
92
93         /**
94          * Copying of objects using this copy constructor is allowed.
95          *
96          * @since 2.0
97          *
98          * @param[in]   value   An instance of %Double
99          */
100         Double(const Double& value);
101
102         /**
103          * This destructor overrides Tizen::Base::Object::~Object().
104          *
105          * @since 2.0
106          */
107         virtual ~Double(void);
108
109         /**
110          * Copying of objects using this copy assignment operator is allowed.
111          *
112          * @since 2.0
113          *
114          * @param[in]   rhs     An instance of %Double
115          */
116         Double& operator =(const Double& rhs);
117
118         /**
119          * Compares two @c double values.
120          *
121          * @since 2.0
122          *
123          * @return              A 32-bit @c signed integer value
124          * @code
125          * <  0  if the value of @c d1 is less than the value of @c d2
126          * == 0  if the value of @c d1 is equal to the value of @c d2
127          * >  0  if the value of @c d1 is greater than the value of @c d2
128          * @endcode
129          * @param[in]   d1      The first @c double value to compare
130          * @param[in]   d2      The second @c double value to compare
131          */
132         static int Compare(double d1, double d2);
133
134         /**
135          * Compares the value of the current instance of %Double with the value of the specified @c signed @c double.
136          *
137          * @since 2.0
138          *
139          * @return              A 32-bit @c signed integer value
140          * @code
141          * <  0  if the value of the current instance is less than the specified @c signed @c double
142          * == 0  if the value of the current instance is equal to the specified @c signed @c double
143          * >  0  if the value of the current instance is greater than the specified @c signed @c double
144          * @endcode
145          * @param[in]   value   A @c signed @c double value
146          */
147         int CompareTo(double value) const;
148
149         /**
150          * Compares the value of the current instance of %Double with the value of the specified instance of %Double.
151          *
152          * @since 2.0
153          *
154          * @return              A 32-bit @c signed integer value
155          * @code
156          * <  0  if the value of the current instance is less than the value of the specified instance
157          * == 0  if the value of the current instance is equal to the value of the specified instance
158          * >  0  if the value of the current instance is greater than the value of the specified instance
159          * @endcode
160          * @param[in]   value   An instance of %Double
161          */
162         int CompareTo(const Double& value) const;
163
164         /**
165          * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Double.
166          *
167          * @since 2.0
168          *
169          * @return              @c true if the value of the specified instance of %Object is equal to the value of the current instance of %Double, @n
170          *                              else @c false
171          * @param[in]   obj An instance of Object to compare
172          * @see                 Tizen::Base::Object::Equals
173          */
174         virtual bool Equals(const Object& obj) const;
175
176         /**
177          *      Gets the hash value of the current instance of %Double.
178          *
179          *      @since 2.0
180          *
181          *      @return         An integer value indicating the hash value of the current instance of %Double
182          *      @remarks        Two equal instances must return the same hash value. For better performance,
183          *                              the used hash function must generate a random distribution for all inputs. @n
184          *                              The default implementation of this method returns the value of the current instance.
185          */
186         virtual int GetHashCode(void) const;
187
188         /**
189         *        Gets the hash value of the specified @c double value.
190         *
191         *        @since 2.0
192         *
193         *        @return        An integer value indicating the hash value of the specified @c double value
194         *        @param[in]   val   A @c double value to get the hash value
195         */
196         static int GetHashCode(double val);
197
198         /**
199          * Parses the specified string representing a numeric value and returns the value as @c signed @c double (as out parameter).
200          *
201          * @since 2.0
202          *
203          * @return              An error code
204          * @param[in]   s                               A unicode representation of @c signed @c double value
205          * @param[out]  ret                     The converted numeric value
206          * @exception   E_SUCCESS               The method is successful.
207          * @exception   E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
208          * @remarks             
209          *                                      - This method guarantees that the original value of out-parameter is not changed when the method returns error.
210          *                                      - The behavior of this method is dependent on the system default locale setting.
211          */
212         static result Parse(const String& s, double& ret);
213
214         /**
215          * Gets the @c signed @c char equivalent of the current instance of %Double.
216          *
217          * @since 2.0
218          *
219          * @return      A @c signed @c char equivalent of the current instance
220          */
221         virtual char ToChar(void) const;
222
223         /**
224          * Gets the @c signed @c short equivalent of the current instance of %Double.
225          *
226          * @since 2.0
227          *
228          * @return      A @c signed @c short equivalent of the current instance
229          */
230         virtual short ToShort(void) const;
231
232         /**
233          * Gets the @c signed @c int equivalent of the current instance of %Double.
234          *
235          * @since 2.0
236          *
237          * @return      A @c signed @c int equivalent of the current instance
238          */
239         virtual int ToInt(void) const;
240
241         /**
242          * Gets the @c signed @c long equivalent of the current instance of %Double.
243          *
244          * @since 2.0
245          *
246          * @return      A @c signed @c long equivalent of the current instance
247          */
248         virtual long ToLong(void) const;
249
250         /**
251          * Gets the @c signed @c long @c long equivalent of the current instance of %Double.
252          *
253          * @since 2.0
254          *
255          * @return      A @c signed @c long @c long equivalent of the current instance
256          */
257         virtual long long ToLongLong(void) const;
258
259         /**
260          * Gets the @c signed @c float equivalent of the current instance of %Double.
261          *
262          * @since 2.0
263          *
264          * @return      A @c signed @c float equivalent of the current instance
265          */
266         virtual float ToFloat(void) const;
267
268         /**
269          * Gets the @c signed @c double equivalent of the current instance of %Double.
270          *
271          * @since 2.0
272          *
273          * @return      A @c signed @c double equivalent of the current instance
274          */
275         virtual double ToDouble(void) const;
276
277         /**
278          * Gets the string representing the value of the current instance of %Double.
279          *
280          * @since 2.0
281          *
282          * @return              A string containing a Unicode representation of the value of the current instance
283          * @remarks             
284          *                              - If the value of the current instance is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
285          *                              produces the result "Infinity". @n
286          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
287          *                              - The behavior of this method is dependent on the system default locale setting.
288          */
289         virtual String ToString(void) const;
290
291         /**
292          * Gets the string representing the specified @c double value.
293          *
294          * @since 2.0
295          *
296          * @return              A string containing a Unicode representation of the specified @c double value
297          * @param[in]   value A @c double value to convert
298          * @remarks             
299          *                              - If the input value is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
300          *                              produces the result "Infinity". @n
301          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
302          *                              - The behavior of this method is dependent on the system default locale setting.
303          */
304         static String ToString(double value);
305
306         /**
307          * Gets the IEEE 754 floating-point "double format" bit layout representation of the specified @c double value.
308          *
309          * @since 2.0
310          *
311          * @return              The bits that represent the floating-point number in the IEEE 754 floating-point "double format" bit layout
312          * @param[in]   value   A @c double value to convert
313          */
314         static long long ToBits(double value);
315
316         /**
317          * Gets the @c double value equivalent of the specified floating-point value represented in the IEEE 754 floating-point "double format" bit layout.
318          *
319          * @since 2.0
320          *
321          * @return              The @c double floating-point value with the same bit pattern
322          * @param[in]   value   The floating-point value to convert
323          */
324         static double ToDoubleFromBits(long long value);
325
326         /**
327          * Checks whether the current value of %Double is equal to negative or positive infinity.
328          *
329          * @since 2.0
330          *
331          * @return              @c true if the current value equals negative or positive infinity, @n
332          *                              else @c false
333          */
334         bool IsInfinity(void) const;
335
336         /**
337          * Checks whether the specified @c double value is equal to negative or positive infinity.
338          *
339          * @since 2.0
340          *
341          * @return              @c true if the specified value equals negative or positive infinity, @n
342          *                              else @c false
343          * @param[in]   value   A @c double value to check
344          */
345
346         static bool IsInfinity(double value);
347
348         /**
349          * Checks whether the current value is Not-a-Number.
350          *
351          * @since 2.0
352          *
353          * @return              @c true if the current value is Not-a-Number, @n
354          *                              else @c false
355          */
356         bool IsNaN(void) const;
357
358         /**
359          * Checks whether the specified value is Not-a-Number.
360          *
361          * @since 2.0
362          *
363          * @return              @c true if the specified value is Not-a-Number, @n
364          *                              else @c false
365          * @param[in]   value   A @c double value to check
366          */
367         static bool IsNaN(double value);
368
369         /**
370          * Gets a constant holding the largest positive finite value of type @c double. @n
371          * This is equal to the value defined in Limit.h of the C library.
372          *
373          * @since 2.0
374          *
375          * @return              A constant holding the largest positive finite value of type @c double
376          */
377         static double GetMaxValue(void);
378
379         /**
380          * Gets a constant holding the smallest positive non-zero value of type @c double. @n
381          * This is equal to the value defined in Limit.h of the C library.
382          *
383          * @since 2.0
384          *
385          * @return              A constant holding the smallest possible non-zero value of type @c double
386          */
387         static double GetMinValue(void);
388
389         /**
390          * A @c double value of this instance.
391          *
392          * @since 2.0
393          */
394         double value;
395
396
397 private:
398         /**
399          *      Checks if the specified @c double value is finite.
400          *
401          *      @since 2.0
402          *
403          *      @return         @c true if the specified value is finite, @n
404          *                              else @c false
405          *      @param[in]      value   A @c double value to check
406          */
407         static bool IsFinite(double d);
408
409         static const int __DBL_MAX_10_EXP = 308;
410
411         friend class _DoubleImpl;
412         class _DoubleImpl * __pDoubleImpl;
413
414 }; // Double
415
416 }} // Tizen::Base
417
418 #endif //_FBASE_DOUBLE_H_