Date: Thursday, March 30, 2006 @ 14:19:07
Author: gilles
Path: /cvsroot/carob/carob/src
Modified: BigDecimal.cpp (1.25 -> 1.26)
Removed signum == 0 optimization that was leading to wrong display of 0.000 (0
with scale 3)
----------------+
BigDecimal.cpp | 34 +++++++++++++++-------------------
1 files changed, 15 insertions(+), 19 deletions(-)
Index: carob/src/BigDecimal.cpp
diff -u carob/src/BigDecimal.cpp:1.25 carob/src/BigDecimal.cpp:1.26
--- carob/src/BigDecimal.cpp:1.25 Thu Mar 23 15:37:04 2006
+++ carob/src/BigDecimal.cpp Thu Mar 30 14:19:07 2006
@@ -323,29 +323,25 @@
// FIXME: this function can be optimized: lots of front-inserts can be avoided
std::wstring BigDecimal::toString(const wchar_t decimal_point) const
{
- wstring sRet(L"0");
- if (signum != 0) // 0 signum means 0 value => no useless computations !
+ //convert to string, then to wstring (no direct mpz->wstring converter)
+ std::ostringstream buffer;
+ buffer << unscaled_value;
+ wstring sRet = fromString(buffer.str());
+ int sRetLength = static_cast<int>(sRet.length());
+ if (scale != 0)
{
- //convert to string, then to wstring (no direct mpz->wstring converter)
- std::ostringstream buffer;
- buffer << unscaled_value;
- sRet = fromString(buffer.str());
- int sRetLength = static_cast<int>(sRet.length());
- if (scale != 0)
+ if (sRetLength <= scale)
{
- if (sRetLength <= scale)
- {
- // add heading zeros as needed
- sRet.insert(0, scale - sRetLength + 1, L'0');
- }
- // insert the decimal point
- sRet.insert(sRet.length()-scale, 1, decimal_point);
+ // add heading zeros as needed
+ sRet.insert(0, scale - sRetLength + 1, L'0');
}
- // and the optional sign
- if (signum < 0)
- sRet.insert(0, L"-");
-
+ // insert the decimal point
+ sRet.insert(sRet.length()-scale, 1, decimal_point);
}
+ // and the optional sign
+ if (signum < 0)
+ sRet.insert(0, L"-");
+
return sRet;
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits