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 %Float class.
21 * @see Tizen::Base::Number
23 * This header file contains the declarations of the %Float class.
25 #ifndef _FBASE_FLOAT_H_
26 #define _FBASE_FLOAT_H_
28 #include <FBaseNumber.h>
30 namespace Tizen { namespace Base
34 * @brief This class is the wrapper class for the @c signed @c float built-in type.
38 * The %Float class represents a single-precision 32-bit floating number. The %Float class wraps a @c float type value. This enables
39 * passing a @c float value to a method that only accepts an instance of Object class. This class provides methods to compare instances
40 * of this type, convert the value of an instance to its string representation, and convert the string representation
41 * of a number to an instance of this type.
43 * The following example demonstrates how to use the %Float class.
49 * using namespace Tizen::Base;
51 * // This method checks whether the given string object contains the string
52 * // representation of the pre-defined minimum float value.
54 * MyClass::Verify(String& string, bool& out)
56 * // Creates and initializes an instance of Double
57 * static const Float MINIMUM(1.23L);
59 * result r = E_SUCCESS;
63 * // Parses the string representation of the numeric value
64 * // Returns f (value as signed float)
65 * r = Float::Parse(string, f);
73 * out = (MINIMUM.CompareTo(f) == 0) ? true: false;
80 class _OSP_EXPORT_ Float
85 * Initializes this instance of %Float with the specified value.
89 * @param[in] value A @c float value
91 Float(float value = 0.0);
95 * Copying of objects using this copy constructor is allowed.
99 * @param[in] value An instance of %Float
101 Float(const Float& value);
104 * This destructor overrides Tizen::Base::Object::~Object().
108 virtual ~Float(void);
111 * Copying of objects using this copy assignment operator is allowed.
115 * @param[in] rhs An instance of %Float
117 Float& operator =(const Float& rhs);
120 * Compares two @c float values.
124 * @return A 32-bit @c signed integer value
126 * < 0 if the value of @c f1 is less than the value of @c f2
127 * == 0 if the value of @c f1 is equal to the value of @c f2
128 * > 0 if the value of @c f1 is greater than the value of @c f2
130 * @param[in] f1 The first @c float value to compare
131 * @param[in] f2 The second @c float value to compare
133 static int Compare(float f1, float f2);
136 * Compares the value of the current instance with the value of the specified instance of the %Float class.
140 * @return A 32-bit @c signed integer value
142 * @li < 0 if the value of the current instance is less than the value of the specified instance
143 * @li == 0 if the value of the current instance is equal to the value of the specified instance
144 * @li > 0 if the value of the current instance is greater than the value of the specified instance
146 * @param[in] value An instance of the %Float class to compare
148 int CompareTo(const Float& value) const;
151 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Float.
155 * @return @c true if the value of the specified instance of Object is equal to the value of the current instance of %Float, @n
157 * @param[in] obj An instance of Object to compare
158 * @see Tizen::Base::Object::Equals()
160 virtual bool Equals(const Object& obj) const;
164 * Gets the hash value of the current instance of %Float.
168 * @return An integer value indicating the hash value of the current instance of %Float
169 * @remarks Two equal instances must return the same hash value. For better performance,
170 * the used hash function must generate a random distribution for all inputs. @n
171 * The default implementation of this method returns the value of the current instance.
173 virtual int GetHashCode(void) const;
176 * Gets the hash value of the specified @c float value.
180 * @return An integer value indicating the hash value of the specified @c float value
181 * @param[in] val A @c float value to get the hash value
183 static int GetHashCode(float val);
186 * Parses the specified string representing a numeric value and returns the value as @c signed @c float (as out parameter).
190 * @return An error code
191 * @param[in] s A unicode string representing a @c signed @c float value
192 * @param[out] ret The numeric representation of the string
193 * @exception E_SUCCESS The method is successful.
194 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
196 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
197 * - The behavior of this method is dependent on the system default locale setting.
198 * @see Tizen::Base::Double::Parse()
200 static result Parse(const String& s, float& ret);
203 * Gets the @c signed @c char equivalent of the current instance of the %Float class.
207 * @return A @c signed @c char equivalent of the current instance
209 virtual char ToChar(void) const;
212 * Gets the @c signed @c short equivalent of the current instance of the %Float class.
216 * @return A @c signed @c short equivalent of the current instance
218 virtual short ToShort(void) const;
221 * Gets the @c signed @c int equivalent of the current instance of the %Float class.
225 * @return A @c signed @c int equivalent of the current instance
227 virtual int ToInt(void) const;
230 * Gets the @c signed @c long equivalent of the current instance of the %Float class.
234 * @return A @c signed @c long equivalent of the current instance
236 virtual long ToLong(void) const;
239 * Gets the @c signed @c long @c long equivalent of the current instance of the %Float class.
243 * @return A @c signed @c long @c long equivalent of the current instance
245 virtual long long ToLongLong(void) const;
248 * Gets the @c signed @c float equivalent of the current instance of the %Float class.
252 * @return A @c signed @c float equivalent of the current instance
254 virtual float ToFloat(void) const;
257 * Gets the @c signed @c double equivalent of the current instance of the %Float class.
261 * @return A @c signed @c double equivalent of the current instance
263 virtual double ToDouble(void) const;
266 * Gets the string representing the value of the current instance of %Float.
270 * @return A string containing a Unicode representation of the value of the current instance
272 * - If the value is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
273 * produces the result "Infinity". @n
274 * 6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
275 * - The behavior of this method is dependent on the system default locale setting.
277 virtual String ToString(void) const;
280 * Gets the string representing the specified @c float value.
284 * @return A string containing a Unicode representation of the specified @c float value
285 * @param[in] value A @c float value to convert
287 * - If the value is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
288 * produces the result "Infinity". @n
289 * 6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
290 * - The behavior of this method is dependent on the system default locale setting.
292 static String ToString(float value);
295 * Gets the IEEE 754 floating-point "single format" bit layout representation of the specified @c float value.
299 * @return The bits that represent the floating-point number in the IEEE 754 floating-point "single format" bit layout
300 * @param[in] value A @c float value to convert
301 * @see Tizen::Base::Double::Parse()
303 static int ToBits(float value);
306 * Gets the @c float value corresponding to the specified floating-point value in the IEEE 754 floating-point "single format" bit layout.
310 * @return The @c float floating-point value with the same bit pattern
311 * @param[in] value A floating-point value in the IEEE 754 floating-point "single format" bit layout
312 * @see Tizen::Base::Double::Parse()
314 static float ToFloatFromBits(int value);
317 * Checks whether the current value of %Float is equal to negative or positive infinity.
321 * @return @c true if the current value equals negative or positive infinity, @n
324 bool IsInfinity(void) const;
327 * Checks whether the specified @c float value is equal to negative or positive infinity.
331 * @return @c true if the specified value equals negative or positive infinity, @n
333 * @param[in] value A @c float value to check
335 static bool IsInfinity(float value);
338 * Checks whether the current value is Not-a-Number.
342 * @return @c true if the current value is Not-a-Number, @n
345 bool IsNaN(void) const;
348 * Checks whether the specified value is Not-a-Number.
352 * @return @c true if the specified value is Not-a-Number, @n
354 * @param[in] value A @c float value to check
356 static bool IsNaN(float value);
359 * Gets a constant holding the largest positive finite value of type @c float. @n
360 * This is equal to the value defined in Limit.h of the C library.
364 * @return A constant holding the largest positive finite value of type @c float
366 static float GetMaxValue(void);
369 * Gets a constant holding the smallest positive non-zero value of type @c float. @n
370 * This is equal to the value defined in Limit.h of the C library.
374 * @return A constant holding the smallest possible non-zero value of type @c float
376 static float GetMinValue(void);
379 * A @c float value of this instance.
388 * Checks if the specified @c float value is finite.
392 * @return @c true if the specified value is finite, @n
394 * @param[in] value A @c float value to check
396 static bool IsFinite(float value);
398 static const int __DBL_MAX_10_EXP = 308;
400 friend class _FloatImpl;
401 class _FloatImpl* __pFloatImpl;
407 #endif //_FBASE_FLOAT_H_