//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
/**
* @file FBaseDouble.cpp
* @brief This is the implementation file for Double class.
- * @see Number
+ * @see Number
*/
-
#include <cfloat>
#include <math.h>
#include <stdio.h>
#include <limits.h>
#include <FBaseDouble.h>
#include <FBaseResult.h>
-#include "FBase_NativeError.h"
#include <FBaseSysLog.h>
-
+#include "FBase_LocalizedNumParser.h"
namespace Tizen { namespace Base
{
bool
Double::Equals(const Object& obj) const
{
- const Double* pOther = dynamic_cast <const Double*>(&obj);
+ const Double* pOther = dynamic_cast< const Double* >(&obj);
if (pOther == null)
{
int
Double::GetHashCode(void) const
{
- double* pTemp = const_cast<double*> (&value);
- int* pValueLow = reinterpret_cast<int*> (pTemp);
+ double* pTemp = const_cast< double* >(&value);
+ int* pValueLow = reinterpret_cast< int* >(pTemp);
int* pValueHigh = pValueLow + 1;
return *pValueLow + *pValueHigh;
}
int
Double::GetHashCode(double val)
{
- int* pValueLow = reinterpret_cast<int*> (&val);
+ int* pValueLow = reinterpret_cast< int* >(&val);
int* pValueHigh = pValueLow + 1;
return *pValueLow + *pValueHigh;
}
result
Double::Parse(const String& s, double& ret)
{
- wchar_t* pEnd = null;
- errno = 0;
- double tmpRet = wcstod(s.GetPointer(), &pEnd);
- SysTryReturnResult(NID_BASE, ((!(!Double::Compare(tmpRet, 0) && errno == EINVAL)) && (pEnd[0] == 0)), E_NUM_FORMAT,
- "Double parse failed with reason (%s). Scan stopped at (%ls)", __ConvertNativeErrorToMessage(errno), pEnd);
- SysTryReturnResult(NID_BASE, !(errno != 0 && (!Double::Compare(tmpRet, HUGE_VAL)|| !Double::Compare(tmpRet, -HUGE_VAL))),
- E_NUM_FORMAT, "Parsed value cannot fit into a Double.");
+ double tmpRet = _LocalizedNumParser::ToDouble(s, "");
+
+ if (IsNaN(tmpRet))
+ {
+ result r = GetLastResult();
+ SysLogException(NID_BASE, r, "[%s] Propagating.", GetErrorMessage(r));
+ return r;
+ }
ret = tmpRet;
return E_SUCCESS;
char
Double::ToChar(void) const
{
- return static_cast<char> (value);
+ return static_cast< char >(value);
}
short
Double::ToShort(void) const
{
- return static_cast<short> (value);
+ return static_cast< short >(value);
}
int
Double::ToInt(void) const
{
- return static_cast<int> (value);
+ return static_cast< int >(value);
}
long
Double::ToLong(void) const
{
- return static_cast<long> (value);
+ return static_cast< long >(value);
}
long long
Double::ToLongLong(void) const
{
- return static_cast<long long> (value);
+ return static_cast< long long >(value);
}
float
Double::ToFloat(void) const
{
- return static_cast<float> (value);
+ return static_cast< float >(value);
}
double
String
Double::ToString(void) const
{
- return(Double::ToString(value));
+ return Double::ToString(value);
}
String
Double::ToString(double value)
{
- const static unsigned int MAX_DIG = 17 + 3;
- const static unsigned int DOUBLE_LENGTH_MAX = __DBL_MAX_10_EXP + MAX_DIG;
-
- if (Double::IsNaN(value))
- {
- return String(L"NaN");
- }
- else if (Double::IsInfinity(value))
- {
- return String(L"Infinity");
- }
- else
- {
- wchar_t sValue[DOUBLE_LENGTH_MAX + 1] = {0, };
- swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%#lg", value);
- return String(sValue);
- }
+ return _LocalizedNumParser::ToString(value, "");
}
long long
bool
Double::IsFinite(double d)
{
- return((isfinite(d) != 0) ? true : false);
+ return isfinite(d);
}
bool
Double::IsInfinity(void) const
{
- return(Double::IsInfinity(value));
+ return Double::IsInfinity(value);
}
bool
Double::IsInfinity(double value)
{
- return(!Double::IsFinite(value));
+ return !Double::IsFinite(value);
}
bool
Double::IsNaN(void) const
{
- return(Double::IsNaN(value));
+ return Double::IsNaN(value);
}
bool
Double::IsNaN(double value)
{
- return((isnan(value) != 0) ? true : false);
+ return isnan(value);
}
double