Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified money tests to test the accuracies of floats #944

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions test/functional/pdo_sqlsrv/pdostatement_format_money_types.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,9 @@ function testFloatTypes($conn, $numDigits)

trace("testFloatTypes: $floatVal1, $floatVal\n");

// Check if the numbers of decimal digits are the same
// It is highly unlikely but not impossible
$numbers = explode('.', $floatStr);
$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";
}
$diff = abs($floatVal1 - $floatVal) / $floatVal;
if ($diff > $epsilon) {
echo "$diff: Expected $floatVal but $floatVal1 returned. \n";
}
}
}
Expand Down
16 changes: 3 additions & 13 deletions test/functional/sqlsrv/sqlsrv_statement_format_money_types.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,10 @@ function testFloatTypes($conn)
for ($i = 0; $i < count($values); $i++) {
$floatStr = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$floatVal = floatval($floatStr);

// Check if the numbers of decimal digits are the same
// It is highly unlikely but not impossible
$numbers = explode('.', $floatStr);
$len = strlen($numbers[1]);
if ($len == $numDigits && $floatVal != $floats[$i]) {
echo "Expected $floats[$i] but returned ";
$diff = abs($floatVal - $floats[$i]) / $floats[$i];
if ($diff > $epsilon) {
echo "$diff: Expected $floats[$i] but returned ";
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 {
Expand Down