Modified money tests to test the accuracies of floats (#944)
This commit is contained in:
parent
27d5f64ff9
commit
d60748e0cd
|
@ -64,17 +64,9 @@ function testFloatTypes($conn, $numDigits)
|
||||||
|
|
||||||
trace("testFloatTypes: $floatVal1, $floatVal\n");
|
trace("testFloatTypes: $floatVal1, $floatVal\n");
|
||||||
|
|
||||||
// Check if the numbers of decimal digits are the same
|
$diff = abs($floatVal1 - $floatVal) / $floatVal;
|
||||||
// It is highly unlikely but not impossible
|
if ($diff > $epsilon) {
|
||||||
$numbers = explode('.', $floatStr);
|
echo "$diff: Expected $floatVal but $floatVal1 returned. \n";
|
||||||
$len = strlen($numbers[1]);
|
|
||||||
if ($len == $numDigits && $floatVal1 != $floatVal) {
|
|
||||||
echo "Expected $floatVal but $floatVal1 returned. \n";
|
|
||||||
} else {
|
|
||||||
$diff = abs($floatVal1 - $floatVal) / $floatVal;
|
|
||||||
if ($diff > $epsilon) {
|
|
||||||
echo "$diff: Expected $floatVal but $floatVal1 returned. \n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,20 +63,10 @@ function testFloatTypes($conn)
|
||||||
for ($i = 0; $i < count($values); $i++) {
|
for ($i = 0; $i < count($values); $i++) {
|
||||||
$floatStr = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
$floatStr = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||||
$floatVal = floatval($floatStr);
|
$floatVal = floatval($floatStr);
|
||||||
|
$diff = abs($floatVal - $floats[$i]) / $floats[$i];
|
||||||
// Check if the numbers of decimal digits are the same
|
if ($diff > $epsilon) {
|
||||||
// It is highly unlikely but not impossible
|
echo "$diff: Expected $floats[$i] but returned ";
|
||||||
$numbers = explode('.', $floatStr);
|
|
||||||
$len = strlen($numbers[1]);
|
|
||||||
if ($len == $numDigits && $floatVal != $floats[$i]) {
|
|
||||||
echo "Expected $floats[$i] but returned ";
|
|
||||||
var_dump($floatVal);
|
var_dump($floatVal);
|
||||||
} else {
|
|
||||||
$diff = abs($floatVal - $floats[$i]) / $floats[$i];
|
|
||||||
if ($diff > $epsilon) {
|
|
||||||
echo "$diff: Expected $floats[$i] but returned ";
|
|
||||||
var_dump($floatVal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue