Last active
January 29, 2019 14:59
-
-
Save bcremer/80d1d53aca40aebe12422ae1c0dc4a96 to your computer and use it in GitHub Desktop.
Why IEEE 754 floating point numbers are a mess to debug
This file contains 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 | |
// Live Demo: https://3v4l.org/GWJFZ | |
// see also: http://0.30000000000000004.com/ | |
var_dump(0.1 + 0.2); // float(0.3) | |
var_dump(0.3); // float(0.3) | |
var_dump(0.1 + 0.2 == 0.3); // bool(false) | |
// Set the number of significant digits displayed in floating point numbers. | |
ini_set('precision', 18); | |
var_dump(0.1 + 0.2); // float(0.300000000000000044) | |
var_dump(0.3); // float(0.299999999999999989) | |
var_dump(0.1 + 0.2 == 0.3); // bool(false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment