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 * This header file contains the declarations of the %Double class.
23 * @see Tizen::Base::Number
25 #ifndef _FBASE_DOUBLE_H_
26 #define _FBASE_DOUBLE_H_
28 #include <FBaseNumber.h>
30 namespace Tizen { namespace Base
34 * @brief This class is the wrapper class for the @c signed @c double built-in type.
38 * The %Double class is the wrapper class for the @c signed @c double built-in type.
40 * It represents a double-precision 64-bit number with values ranging from negative
41 * 1.79769313486232e308 to positive 1.79769313486232e308. This class is useful when passing a @c double
42 * value to a method expecting an instance of Object, such as Tizen::Base::Collection::Queue or
43 * Tizen::Base::Collection::Stack. Furthermore, this class provides methods for converting
44 * %Double (and @c double) to String, and %String to %Double (and @c double).
46 * The following example demonstrates how to use the %Double class.
52 * using namespace Tizen::Base;
54 * // This method checks whether the given string object contains a string
55 * // representation of the pre-defined minimum double value.
57 * MyClass::Verify(const String& string, bool& out)
59 * static const Double MINIMUM(1.23L);
61 * result r = E_SUCCESS;
64 * r = Double::Parse(string, d);
70 * out = (MINIMUM.CompareTo(d) == 0) ? true: false;
78 class _OSP_EXPORT_ Double
83 * Initializes this instance of %Double with the specified value.
87 * @param[in] value The @c double value
89 Double(double value = 0.0L);
92 * Copying of objects using this copy constructor is allowed.
96 * @param[in] value An instance of %Double to copy
98 Double(const Double& value);
101 * This destructor overrides Tizen::Base::Object::~Object().
105 virtual ~Double(void);
108 * Copying of objects using this copy assignment operator is allowed.
112 * @param[in] rhs An instance of %Double to copy
114 Double& operator =(const Double& rhs);
117 * Compares two @c double values.
121 * @return The 32-bit @c signed integer value
123 * < 0 if the value of d1 is less than the value of d2
124 * == 0 if the value of d1 is equal to the value of d2
125 * > 0 if the value of d1 is greater than the value of d2
127 * @param[in] d1 The first @c double value to compare
128 * @param[in] d2 The second @c double value to compare
130 static int Compare(double d1, double d2);
133 * Compares the value of the current instance of %Double with the value of the specified @c signed @c double.
137 * @return The 32-bit @c signed integer value
139 * < 0 if the value of the current instance is less than the specified signed double
140 * == 0 if the value of the current instance is equal to the specified signed double
141 * > 0 if the value of the current instance is greater than the specified signed double
143 * @param[in] value A @c signed @c double value
145 int CompareTo(double value) const;
148 * Compares the value of the current instance of %Double with the value of the specified instance of %Double.
152 * @return The 32-bit @c signed integer value
154 * < 0 if the value of the current instance is less than the value of the specified instance
155 * == 0 if the value of the current instance is equal to the value of the specified instance
156 * > 0 if the value of the current instance is greater than the value of the specified instance
158 * @param[in] value An instance of %Double
160 int CompareTo(const Double& value) const;
163 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Double.
167 * @return @c true if the value of the specified instance of Object is equal to the value of the current instance of %Double, @n
169 * @param[in] obj An instance of Object to compare
170 * @see Tizen::Base::Object::Equals()
172 virtual bool Equals(const Object& obj) const;
175 * Gets the hash value of the current instance of %Double.
179 * @return The integer value that indicates the hash value of the current instance of %Double
181 * - Two equal instances must return the same hash value. @n
182 * For better performance, the used hash function must generate a random distribution for all the inputs.
183 * - The default implementation of this method returns the value of the current instance.
185 virtual int GetHashCode(void) const;
188 * Gets the hash value of the specified @c double value.
192 * @return The integer value that indicates the hash value of the specified @c double value
193 * @param[in] val The @c double value to get the hash value
195 static int GetHashCode(double val);
198 * Parses the specified string that represents a numeric value and returns the value as @c signed @c double (as out parameter).
202 * @return An error code
203 * @param[in] s The unicode representation of @c signed @c double value
204 * @param[out] ret The converted numeric value
205 * @exception E_SUCCESS The method is successful.
206 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
208 * - This method guarantees that the original value of the out-parameter is not changed when the method returns an error.
209 * - The behavior of this method is dependent on the system default locale setting.
211 static result Parse(const String& s, double& ret);
214 * Gets the @c signed @c char equivalent of the current instance of %Double.
218 * @return The @c signed @c char equivalent of the current instance
220 virtual char ToChar(void) const;
223 * Gets the @c signed @c short equivalent of the current instance of %Double.
227 * @return The @c signed @c short equivalent of the current instance
229 virtual short ToShort(void) const;
232 * Gets the @c signed @c int equivalent of the current instance of %Double.
236 * @return The @c signed @c int equivalent of the current instance
238 virtual int ToInt(void) const;
241 * Gets the @c signed @c long equivalent of the current instance of %Double.
245 * @return The @c signed @c long equivalent of the current instance
247 virtual long ToLong(void) const;
250 * Gets the @c signed @c long @c long equivalent of the current instance of %Double.
254 * @return The @c signed @c long @c long equivalent of the current instance
256 virtual long long ToLongLong(void) const;
259 * Gets the @c signed @c float equivalent of the current instance of %Double.
263 * @return The @c signed @c float equivalent of the current instance
265 virtual float ToFloat(void) const;
268 * Gets the @c signed @c double equivalent of the current instance of %Double.
272 * @return The @c signed @c double equivalent of the current instance
274 virtual double ToDouble(void) const;
277 * Gets the string that represents the value of the current instance of %Double.
281 * @return The string that contains the Unicode representation of the value of the current instance
283 * - If the value of the current instance is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
284 * produces the result "Infinity". @n
285 * 6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
286 * - The behavior of this method is dependent on the system default locale setting.
288 virtual String ToString(void) const;
291 * Gets the string that represents the specified @c double value.
295 * @return The string that contains the Unicode representation of the specified @c double value
296 * @param[in] value The @c double value to convert
298 * - If the input value is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
299 * produces the result "Infinity". @n
300 * 6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
301 * - The behavior of this method is dependent on the system default locale setting.
303 static String ToString(double value);
306 * Gets the IEEE 754 floating-point "double format" bit layout representation of the specified @c double value.
310 * @return The bits that represent the floating-point number in the IEEE 754 floating-point "double format" bit layout
311 * @param[in] value The @c double value to convert
313 static long long ToBits(double value);
316 * Gets the @c double value equivalent of the specified floating-point value represented in the IEEE 754 floating-point "double format" bit layout.
320 * @return The @c double floating-point value with the same bit pattern
321 * @param[in] value The floating-point value to convert
323 static double ToDoubleFromBits(long long value);
326 * Checks whether the current value of %Double is equal to the negative or positive infinity.
330 * @return @c true if the current value equals the negative or positive infinity, @n
333 bool IsInfinity(void) const;
336 * Checks whether the specified @c double value is equal to the negative or positive infinity.
340 * @return @c true if the specified value equals the negative or positive infinity, @n
342 * @param[in] value The @c double value to check
344 static bool IsInfinity(double value);
347 * Checks whether the current value is Not-a-Number.
351 * @return @c true if the current value is Not-a-Number, @n
354 bool IsNaN(void) const;
357 * Checks whether the specified value is Not-a-Number.
361 * @return @c true if the specified value is Not-a-Number, @n
363 * @param[in] value The @c double value to check
365 static bool IsNaN(double value);
368 * Gets the constant holding the largest positive finite value of type @c double. @n
369 * This is equal to the value defined in Limit.h of the C library.
373 * @return The constant holding the largest positive finite value of type @c double
375 static double GetMaxValue(void);
378 * Gets the constant holding the smallest positive non-zero value of type @c double. @n
379 * This is equal to the value defined in Limit.h of the C library.
383 * @return The constant holding the smallest possible non-zero value of type @c double
385 static double GetMinValue(void);
388 * The @c double value of this instance.
396 * Checks if the specified @c double value is finite.
400 * @return @c true if the specified value is finite, @n
402 * @param[in] value A @c double value to check
404 static bool IsFinite(double d);
406 static const int __DBL_MAX_10_EXP = 308;
408 friend class _DoubleImpl;
409 class _DoubleImpl* __pDoubleImpl;
413 #endif //_FBASE_DOUBLE_H_