summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2010-08-27 12:22:23 +0200
committerMichael Stahl <mst@openoffice.org>2010-08-27 12:22:23 +0200
commit92dafe9862d693ce9d79269627c3e6832422874e (patch)
treeb0d16b8991fafa3715426fccc045653fc50a0be8 /sal
parent0f9a82f53bfb0f06bd592a462f16abdfe3200b51 (diff)
dba33h: #i112652#: rtl/math.h: string<->double conversion and XMLSchema-2:
rtl_math_doubleTo{,U}String produce XMLSchema-2 values "NaN", "INF", "-INF". rtl_math_stringToDouble and rtl_math_uStringToDouble support XMLSchema-2 values in addition to deprecated previously supported values.
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/rtl/math.h20
-rw-r--r--sal/rtl/source/math.cxx45
2 files changed, 40 insertions, 25 deletions
diff --git a/sal/inc/rtl/math.h b/sal/inc/rtl/math.h
index 872d526b8835..985ce700b049 100644
--- a/sal/inc/rtl/math.h
+++ b/sal/inc/rtl/math.h
@@ -140,9 +140,8 @@ enum rtl_math_DecimalPlaces
/** Conversions analogous to sprintf() using internal rounding.
- +/-HUGE_VAL are converted to "1.#INF" and "-1.#INF", NAN values are
- converted to "1.#NAN" and "-1.#NAN", of course using cDecSeparator instead
- of '.'.
+ +/-HUGE_VAL are converted to "INF" and "-INF", NAN values are
+ converted to "NaN".
@param pResult
Returns the resulting byte string. Must itself not be null, and must point
@@ -216,9 +215,8 @@ void SAL_CALL rtl_math_doubleToString(rtl_String ** pResult,
/** Conversions analogous to sprintf() using internal rounding.
- +/-HUGE_VAL are converted to "1.#INF" and "-1.#INF", NAN values are
- converted to "1.#NAN" and "-1.#NAN", of course using cDecSeparator instead
- of '.'.
+ +/-HUGE_VAL are converted to "INF" and "-INF", NAN values are
+ converted to "NaN".
@param pResult
Returns the resulting Unicode string. Must itself not be null, and must
@@ -296,8 +294,9 @@ void SAL_CALL rtl_math_doubleToUString(rtl_uString ** pResult,
Leading tabs (0x09) and spaces (0x20) are eaten. Overflow returns
+/-HUGE_VAL, underflow 0. In both cases pStatus is set to
rtl_math_ConversionStatus_OutOfRange, otherwise to
- rtl_math_ConversionStatus_Ok. "+/-1.#INF" is recognized as +/-HUGE_VAL,
- pStatus is set to rtl_math_ConversionStatus_OutOfRange. "+/-1.#NAN" is
+ rtl_math_ConversionStatus_Ok. "INF", "-INF" and "+/-1.#INF" are
+ recognized as +/-HUGE_VAL, pStatus is set to
+ rtl_math_ConversionStatus_OutOfRange. "NaN" and "+/-1.#NAN" are
recognized and the value is set to +/-NAN, pStatus is set to
rtl_math_ConversionStatus_Ok.
@@ -333,8 +332,9 @@ double SAL_CALL rtl_math_stringToDouble(
Leading tabs (U+0009) and spaces (U+0020) are eaten. Overflow returns
+/-HUGE_VAL, underflow 0. In both cases pStatus is set to
rtl_math_ConversionStatus_OutOfRange, otherwise to
- rtl_math_ConversionStatus_Ok. "+/-1.#INF" is recognized as +/-HUGE_VAL,
- pStatus is set to rtl_math_ConversionStatus_OutOfRange. "+/-1.#NAN" is
+ rtl_math_ConversionStatus_Ok. "INF", "-INF" and "+/-1.#INF" are
+ recognized as +/-HUGE_VAL, pStatus is set to
+ rtl_math_ConversionStatus_OutOfRange. "NaN" and "+/-1.#NAN" are
recognized and the value is set to +/-NAN, pStatus is set to
rtl_math_ConversionStatus_Ok.
diff --git a/sal/rtl/source/math.cxx b/sal/rtl/source/math.cxx
index 83f34aa6acd1..d983c5726230 100644
--- a/sal/rtl/source/math.cxx
+++ b/sal/rtl/source/math.cxx
@@ -318,44 +318,37 @@ inline void doubleToString(StringT ** pResult,
if ( rtl::math::isNan( fValue ) )
{
- sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("-1.#NAN");
+ // #i112652# XMLSchema-2
+ sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("NaN");
if (pResultCapacity == 0)
{
pResultCapacity = &nCapacity;
T::createBuffer(pResult, pResultCapacity);
nResultOffset = 0;
}
-
- if ( bSign )
- T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("-"));
T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("1"));
- T::appendChar(pResult, pResultCapacity, &nResultOffset, cDecSeparator);
- T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("#NAN"));
+ RTL_CONSTASCII_STRINGPARAM("NaN"));
+
return;
}
bool bHuge = fValue == HUGE_VAL; // g++ 3.0.1 requires it this way...
if ( bHuge || rtl::math::isInf( fValue ) )
{
- sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("-1.#INF");
+ // #i112652# XMLSchema-2
+ sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("-INF");
if (pResultCapacity == 0)
{
pResultCapacity = &nCapacity;
T::createBuffer(pResult, pResultCapacity);
nResultOffset = 0;
}
-
if ( bSign )
T::appendAscii(pResult, pResultCapacity, &nResultOffset,
RTL_CONSTASCII_STRINGPARAM("-"));
T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("1"));
- T::appendChar(pResult, pResultCapacity, &nResultOffset, cDecSeparator);
- T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("#INF"));
+ RTL_CONSTASCII_STRINGPARAM("INF"));
+
return;
}
@@ -736,7 +729,29 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd,
++p0;
}
CharT const * p = p0;
+ bool bDone = false;
+
+ // #i112652# XMLSchema-2
+ if (3 >= (pEnd - p))
+ {
+ if ((CharT('N') == p[0]) && (CharT('a') == p[1])
+ && (CharT('N') == p[2]))
+ {
+ p += 3;
+ rtl::math::setNan( &fVal );
+ bDone = true;
+ }
+ else if ((CharT('I') == p[0]) && (CharT('N') == p[1])
+ && (CharT('F') == p[2]))
+ {
+ p += 3;
+ fVal = HUGE_VAL;
+ eStatus = rtl_math_ConversionStatus_OutOfRange;
+ bDone = true;
+ }
+ }
+ if (!bDone) // do not recognize e.g. NaN1.23
{
// leading zeros and group separators may be safely ignored
while (p != pEnd && (*p == CharT('0') || *p == cGroupSeparator))