2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This is the header file for the %Double class.
21 * @see Tizen::Base::Number
23 * This header file contains the declarations of the %Double class.
25 #ifndef _FBASE_DOUBLE_H_
26 #define _FBASE_DOUBLE_H_
28 #include <FBaseNumber.h>
31 namespace Tizen { namespace Base
35 * @brief This class is the wrapper class for the @c signed @c double built-in type.
39 * The %Double class is the wrapper class for the @c signed @c double built-in type.
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).
47 * The following example demonstrates how to use the %Double class.
53 * using namespace Tizen::Base;
55 * // This method checks whether the given string object contains a string
56 * // representation of the pre-defined minimum double value.
58 * MyClass::Verify(const String& string, bool& out)
60 * static const Double MINIMUM(1.23L);
62 * result r = E_SUCCESS;
65 * r = Double::Parse(string, d);
71 * out = (MINIMUM.CompareTo(d) == 0) ? true: false;
79 class _OSP_EXPORT_ Double
84 * Initializes this instance of %Double with the specified value.
88 * @param[in] value A @c double value
90 Double(double value = 0.0L);
94 * Copying of objects using this copy constructor is allowed.
98 * @param[in] value An instance of %Double
100 Double(const Double& value);
103 * This destructor overrides Tizen::Base::Object::~Object().
107 virtual ~Double(void);
110 * Copying of objects using this copy assignment operator is allowed.
114 * @param[in] rhs An instance of %Double
116 Double& operator =(const Double& rhs);
119 * Compares two @c double values.
123 * @return A 32-bit @c signed integer value
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
129 * @param[in] d1 The first @c double value to compare
130 * @param[in] d2 The second @c double value to compare
132 static int Compare(double d1, double d2);
135 * Compares the value of the current instance of %Double with the value of the specified @c signed @c double.
139 * @return A 32-bit @c signed integer value
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
145 * @param[in] value A @c signed @c double value
147 int CompareTo(double value) const;
150 * Compares the value of the current instance of %Double with the value of the specified instance of %Double.
154 * @return A 32-bit @c signed integer value
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
160 * @param[in] value An instance of %Double
162 int CompareTo(const Double& value) const;
165 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Double.
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
171 * @param[in] obj An instance of Object to compare
172 * @see Tizen::Base::Object::Equals
174 virtual bool Equals(const Object& obj) const;
177 * Gets the hash value of the current instance of %Double.
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.
186 virtual int GetHashCode(void) const;
189 * Gets the hash value of the specified @c double value.
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
196 static int GetHashCode(double val);
199 * Parses the specified string representing a numeric value and returns the value as @c signed @c double (as out parameter).
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.
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.
212 static result Parse(const String& s, double& ret);
215 * Gets the @c signed @c char equivalent of the current instance of %Double.
219 * @return A @c signed @c char equivalent of the current instance
221 virtual char ToChar(void) const;
224 * Gets the @c signed @c short equivalent of the current instance of %Double.
228 * @return A @c signed @c short equivalent of the current instance
230 virtual short ToShort(void) const;
233 * Gets the @c signed @c int equivalent of the current instance of %Double.
237 * @return A @c signed @c int equivalent of the current instance
239 virtual int ToInt(void) const;
242 * Gets the @c signed @c long equivalent of the current instance of %Double.
246 * @return A @c signed @c long equivalent of the current instance
248 virtual long ToLong(void) const;
251 * Gets the @c signed @c long @c long equivalent of the current instance of %Double.
255 * @return A @c signed @c long @c long equivalent of the current instance
257 virtual long long ToLongLong(void) const;
260 * Gets the @c signed @c float equivalent of the current instance of %Double.
264 * @return A @c signed @c float equivalent of the current instance
266 virtual float ToFloat(void) const;
269 * Gets the @c signed @c double equivalent of the current instance of %Double.
273 * @return A @c signed @c double equivalent of the current instance
275 virtual double ToDouble(void) const;
278 * Gets the string representing the value of the current instance of %Double.
282 * @return A string containing a Unicode representation of the value of the current instance
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.
289 virtual String ToString(void) const;
292 * Gets the string representing the specified @c double value.
296 * @return A string containing a Unicode representation of the specified @c double value
297 * @param[in] value A @c double value to convert
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.
304 static String ToString(double value);
307 * Gets the IEEE 754 floating-point "double format" bit layout representation of the specified @c double value.
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
314 static long long ToBits(double value);
317 * Gets the @c double value equivalent of the specified floating-point value represented in the IEEE 754 floating-point "double format" bit layout.
321 * @return The @c double floating-point value with the same bit pattern
322 * @param[in] value The floating-point value to convert
324 static double ToDoubleFromBits(long long value);
327 * Checks whether the current value of %Double is equal to negative or positive infinity.
331 * @return @c true if the current value equals negative or positive infinity, @n
334 bool IsInfinity(void) const;
337 * Checks whether the specified @c double value is equal to negative or positive infinity.
341 * @return @c true if the specified value equals negative or positive infinity, @n
343 * @param[in] value A @c double value to check
346 static bool IsInfinity(double value);
349 * Checks whether the current value is Not-a-Number.
353 * @return @c true if the current value is Not-a-Number, @n
356 bool IsNaN(void) const;
359 * Checks whether the specified value is Not-a-Number.
363 * @return @c true if the specified value is Not-a-Number, @n
365 * @param[in] value A @c double value to check
367 static bool IsNaN(double value);
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.
375 * @return A constant holding the largest positive finite value of type @c double
377 static double GetMaxValue(void);
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.
385 * @return A constant holding the smallest possible non-zero value of type @c double
387 static double GetMinValue(void);
390 * A @c double value of this instance.
399 * Checks if the specified @c double value is finite.
403 * @return @c true if the specified value is finite, @n
405 * @param[in] value A @c double value to check
407 static bool IsFinite(double d);
409 static const int __DBL_MAX_10_EXP = 308;
411 friend class _DoubleImpl;
412 class _DoubleImpl * __pDoubleImpl;
418 #endif //_FBASE_DOUBLE_H_