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