|
@@ -147,6 +147,9 @@ protected:
|
|
|
{
|
|
|
char temp[80];
|
|
|
value.getCString(sizeof(temp), temp);
|
|
|
+ const char * unknown = strchr(expected, 'x');
|
|
|
+ if (unknown && temp[unknown-expected])
|
|
|
+ temp[unknown-expected] = 'x';
|
|
|
cppunit_assert(strcmp(expected, temp) == 0, "ERROR: checkDecimal/char: expected '%s', got '%s'", expected, temp);
|
|
|
}
|
|
|
|
|
@@ -440,6 +443,8 @@ protected:
|
|
|
testMultiply("0.000000000000000101","0.0000000000000000099009901","0");
|
|
|
testMultiply("0.000000000000000101","0.000000000000000099009901","0.00000000000000000000000000000001");
|
|
|
testMultiply("109", "9174311926605504587155963302.75229357798165137614678899082568", "999999999999999999999999999999.99999999999999999999999999999912");
|
|
|
+ testMultiply("109", "9174311926605504587155963302.75229357798165137614678899082569", "1000000000000000000000000000000.00000000000000000000000000000021");
|
|
|
+ testMultiply("9999999999.999999999999999999999999999999","9999999999.999999999999999999999999999999","99999999999999999999.99999999999999999998"); // actually 99999999999999999999.999999999999999999980000000000000000000000000000000000000001
|
|
|
|
|
|
Decimal a = "9999999999999999";
|
|
|
Decimal b = "10000000000000002";
|
|
@@ -456,10 +461,11 @@ protected:
|
|
|
testDivide("125","5","25");
|
|
|
testDivide("99980001","9999","9999");
|
|
|
testDivide("0.1234","10000000000000000000000000000000","0.00000000000000000000000000000001");
|
|
|
- testDivide("0.1234","20000000000000000000000000000000","0");
|
|
|
+ testDivide("0.1234","20000000000000000000000000000000","0.00000000000000000000000000000001");
|
|
|
+ testDivide("0.1234","30000000000000000000000000000000","0");
|
|
|
testDivide("1","0.00000000000000000000000000000002", "50000000000000000000000000000000");
|
|
|
testDivide("1","3", "0.33333333333333333333333333333333");
|
|
|
- testDivide("1000000000000000000000000000000","109", "9174311926605504587155963302.75229357798165137614678899082568");
|
|
|
+ testDivide("1000000000000000000000000000000","109", "9174311926605504587155963302.75229357798165137614678899082569");
|
|
|
testModulus("1000000000000000000000000000000","109", "82");
|
|
|
testModulus("10","5","0");
|
|
|
testModulus("10","6","4");
|
|
@@ -500,7 +506,7 @@ protected:
|
|
|
void testBcdPower()
|
|
|
{
|
|
|
//MORE: Test power functions...
|
|
|
- const char * values[] = { "0.00001", "10000", "-1", "-10", "1.0001", "9.99" };
|
|
|
+ const char * values[] = { "10000", "-1", "-10", "1.0001", "9.99" };
|
|
|
Decimal one(1);
|
|
|
for (unsigned idx = 0; idx < _elements_in(values); idx++)
|
|
|
{
|
|
@@ -537,18 +543,21 @@ protected:
|
|
|
}
|
|
|
|
|
|
//internal consistency test, but liable to rounding errors....
|
|
|
- if (true)
|
|
|
+ Decimal product(powerValue1);
|
|
|
+ product.multiply(powerValue2);
|
|
|
+ if (power && (product.compareNull() != 0) && (product.compare(one) != 0))
|
|
|
{
|
|
|
- powerValue1.multiply(powerValue2);
|
|
|
- if (power && (powerValue1.compareNull() != 0) && (powerValue1.compare(one) != 0))
|
|
|
- {
|
|
|
- Decimal diff = powerValue1;
|
|
|
- diff.subtract(one);
|
|
|
- one.getCString(sizeof(temp1), temp1);
|
|
|
- powerValue1.getCString(sizeof(temp2), temp2);
|
|
|
- diff.getCString(sizeof(temp3), temp3);
|
|
|
- success &= check(false, "ERROR: %s^%d^-%d=%s (expected %s) diff %s", values[idx], power, power, temp2, temp1, temp3);
|
|
|
- }
|
|
|
+ char temp4[80];
|
|
|
+ char temp5[80];
|
|
|
+ Decimal diff = product;
|
|
|
+ diff.subtract(one);
|
|
|
+ one.getCString(sizeof(temp1), temp1);
|
|
|
+ product.getCString(sizeof(temp2), temp2);
|
|
|
+ diff.getCString(sizeof(temp3), temp3);
|
|
|
+ powerValue1.getCString(sizeof(temp4), temp4);
|
|
|
+ powerValue2.getCString(sizeof(temp5), temp5);
|
|
|
+ //Report rounding errors, but don't trigger a failure
|
|
|
+ check(false, "ERROR: %s^%d^-%d=%s (expected %s) diff %s [%s*%s]", values[idx], power, power, temp2, temp1, temp3, temp4, temp5);
|
|
|
}
|
|
|
|
|
|
sofar1.multiply(value);
|
|
@@ -565,13 +574,14 @@ protected:
|
|
|
checkDecimal(-9999999.12, "-9999999.12");
|
|
|
checkDecimal(9999999.12345678, "9999999.12345678");
|
|
|
checkDecimal(-9999999.12345678, "-9999999.12345678");
|
|
|
- checkDecimal(9999999.123456789, "9999999.12345679");
|
|
|
- checkDecimal(-9999999.123456789, "-9999999.12345679");
|
|
|
-
|
|
|
- checkDecimal(99999991234567800.00, "99999991234567800");
|
|
|
- checkDecimal(-99999991234567800.00, "-99999991234567800");
|
|
|
- checkDecimal(99999991234567890.00, "99999991234567900");
|
|
|
- checkDecimal(-99999991234567890.00, "-99999991234567900");
|
|
|
+ checkDecimal(9999999.123456789, "9999999.123456789");
|
|
|
+ checkDecimal(-9999999.123456789, "-9999999.123456789");
|
|
|
+
|
|
|
+ //MORE: The exact values are out of our control.
|
|
|
+ //Real->decimal extracts 16 decimal digits, but only 15.9 are significant, so the last digit cannot be guaranteed.
|
|
|
+ checkDecimal(91999991234567800.00, "919999912345678x0");
|
|
|
+ checkDecimal(-91999991234567800.00, "-919999912345678x0");
|
|
|
+ checkDecimal(91999991234567123.00, "919999912345671x0");
|
|
|
|
|
|
// in vc++ these real constants seem to only have 14 significant digits
|
|
|
// checkDecimal(0.99999991234567800, "0.999999912345678");
|