summaryrefslogtreecommitdiff
path: root/test/unit/t_amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-06-15 17:40:17 +0100
committerJohn Wiegley <johnw@newartisans.com>2009-06-15 17:52:38 +0100
commit092bda14359d414e1b1e62184cc4d927a4154348 (patch)
tree6af29dedd499de5944bc1998b0a74165b84648cf /test/unit/t_amount.cc
parent981dc41eb7d0bfd04c23c4f208f76e986cd7007a (diff)
downloadfork-ledger-092bda14359d414e1b1e62184cc4d927a4154348.tar.gz
fork-ledger-092bda14359d414e1b1e62184cc4d927a4154348.tar.bz2
fork-ledger-092bda14359d414e1b1e62184cc4d927a4154348.zip
Don't increase precision so much when dividing
Slow the increase in internal precision when dividing amounts. Use "--debug amount.convert" if you wish to see this logic in action, if a case where incorrect rounding is suspected comes up. Fixes B68FFB0D-A9A0-479C-A6C0-68853F229333
Diffstat (limited to 'test/unit/t_amount.cc')
-rw-r--r--test/unit/t_amount.cc40
1 files changed, 20 insertions, 20 deletions
diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc
index 8aa67137..ba863ca7 100644
--- a/test/unit/t_amount.cc
+++ b/test/unit/t_amount.cc
@@ -866,7 +866,7 @@ void AmountTestCase::testIntegerDivision()
x1 /= amount_t(456L);
assertEqual(string("0.269737"), x1.to_string());
x1 /= 456L;
- assertEqual(string("0.000591528162511542"), x1.to_string());
+ assertEqual(string("0.000591528163"), x1.to_string());
amount_t x4("123456789123456789123456789");
amount_t y4("56");
@@ -889,32 +889,32 @@ void AmountTestCase::testFractionalDivision()
amount_t y1("456.456");
assertThrow(x1 / 0L, amount_error);
- assertEqual(string("0.00812195934"), (amount_t("1.0") / x1).to_string());
- assertEqual(string("0.00812195934"), (amount_t("1.0") / x1).to_string());
+ assertEqual(string("0.0081219593"), (amount_t("1.0") / x1).to_string());
+ assertEqual(string("0.0081219593"), (amount_t("1.0") / x1).to_string());
assertEqual(x1, x1 / amount_t("1.0"));
- assertEqual(string("0.00812195934"), (amount_t("1.0") / x1).to_string());
- assertEqual(string("0.00812195934"), (amount_t("1.0") / x1).to_string());
+ assertEqual(string("0.0081219593"), (amount_t("1.0") / x1).to_string());
+ assertEqual(string("0.0081219593"), (amount_t("1.0") / x1).to_string());
assertEqual(- x1, x1 / amount_t("-1.0"));
- assertEqual(string("-0.00812195934"), (amount_t("-1.0") / x1).to_string());
- assertEqual(string("-0.00812195934"), (amount_t("-1.0") / x1).to_string());
- assertEqual(string("0.269736842105263"), (x1 / y1).to_string());
- assertEqual(string("3.707317073170732"), (y1 / x1).to_string());
- assertEqual(string("0.269736842105263"), (x1 / amount_t("456.456")).to_string());
- assertEqual(string("3.707317073170732"), (amount_t("456.456") / x1).to_string());
- assertEqual(string("3.707317073170732"), (amount_t("456.456") / x1).to_string());
+ assertEqual(string("-0.0081219593"), (amount_t("-1.0") / x1).to_string());
+ assertEqual(string("-0.0081219593"), (amount_t("-1.0") / x1).to_string());
+ assertEqual(string("0.269736842105"), (x1 / y1).to_string());
+ assertEqual(string("3.707317073171"), (y1 / x1).to_string());
+ assertEqual(string("0.269736842105"), (x1 / amount_t("456.456")).to_string());
+ assertEqual(string("3.707317073171"), (amount_t("456.456") / x1).to_string());
+ assertEqual(string("3.707317073171"), (amount_t("456.456") / x1).to_string());
x1 /= amount_t("456.456");
- assertEqual(string("0.269736842105263"), x1.to_string());
+ assertEqual(string("0.269736842105"), x1.to_string());
x1 /= amount_t("456.456");
- assertEqual(string("0.000590937225286255757169884601508201951"), x1.to_string());
+ assertEqual(string("0.000590937225286255757"), x1.to_string());
x1 /= 456L;
- assertEqual(string("0.00000129591496773301701133746621429767819329289006668733529828959526392431755859036"), x1.to_string());
+ assertEqual(string("0.000001295914967733017011337"), x1.to_string());
amount_t x4("1234567891234567.89123456789");
amount_t y4("56.789");
assertEqual(amount_t("1.0"), x4 / x4);
- assertEqual(string("21739560323910.7554497273748437197344556164046"), (x4 / y4).to_string());
+ assertEqual(string("21739560323910.75544972737484371973"), (x4 / y4).to_string());
assertValid(x1);
assertValid(y1);
@@ -946,9 +946,9 @@ void AmountTestCase::testCommodityDivision()
// Internal amounts retain their precision, even when being
// converted to strings
assertEqual(string("$0.99727201"), (x1 / x2).to_fullstring());
- assertEqual(string("$1.00273545321637426901"), (x2 / x1).to_fullstring());
+ assertEqual(string("$1.00273545321637"), (x2 / x1).to_fullstring());
assertEqual(string("$1.00"), (x1 / x2).to_string());
- assertEqual(string("$1.00273545321637426901"), (x2 / x1).to_string());
+ assertEqual(string("$1.00273545321637"), (x2 / x1).to_string());
assertThrow(x1 / x0, amount_error);
assertThrow(x0 / x1, amount_error);
@@ -970,9 +970,9 @@ void AmountTestCase::testCommodityDivision()
amount_t x7(internalAmount("$123456789123456789.123456789123456789"));
assertEqual(amount_t("$1"), x7 / x7);
- assertEqual(string("$0.0019216115121765559608381226612019501046413574469262"),
+ assertEqual(string("$0.0019216115121765559608381226612019501"),
(x6 / x7).to_fullstring());
- assertEqual(string("$520.39654928343335571379527154924040947271699678158689736256"),
+ assertEqual(string("$520.39654928343335571379527154924040947272"),
(x7 / x6).to_fullstring());
assertValid(x1);