Re: Math Weirdness

From: Date: Tue, 15 Jul 2008 18:17:35 +0000
Subject: Re: Math Weirdness
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-276872@lists.php.net to get a copy of this message
Robin Vickery schreef:
2008/7/15 tedd <tedd.sperling@gmail.com>:
I said: "Round-off errors normally don't enter into things unless your doing multiplication and division operations." And that is not "Bull" -- it's true. You can add and subtract all the floating point numbers (the one's we are talking about here) you want without any rounding errors whatsoever.
$ php -r 'echo 0.7 - 0.2 == 0.5 ? "true\n" : "false\n";' false The operation you do isn't important. You just can't represent certain numbers exactly in binary, just as you can't represent 1/3 exactly in decimal. They have to be rounded internally.
which makes php casting so much fun: $ php -r 'echo (string)(0.7 - 0.2) == 0.5 ? "true\n" : "false\n";' true
-robin


« previous php.general (#276872) next »