Created
April 9, 2020 14:45
-
-
Save caramelchocolate/58a8360795db48027bef411825c34a40 to your computer and use it in GitHub Desktop.
Round-off error example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = 0.1 + 0.1 + 0.1; | |
$b = 0.3; | |
if ($a != $b) { | |
echo "Round-off error" . PHP_EOL; | |
} | |
$a = (0.1 * 0.1) * 30; | |
$b = 0.3; | |
if ($a != $b) { | |
echo "Round-off error" . PHP_EOL; | |
} | |
$a = (0.1 * 0.1) / 0.1; | |
$b = 0.1; | |
if ($a != $b) { | |
echo "Round-off error" . PHP_EOL; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment