Re: Simple math failing - PHP Bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 31 Oct 2004 21:52:32 -0700, Brian T. Allen <brian@xxxxxxxxxxxxxxx> wrote:

Hi,

OK, I'm totally stumped by this. This should be the simplest math imaginable (addition and subtraction), but PHP is coming up with the wrong answer!

[snip]
Is this legitimately bad math on the part of PHP?

Thanks,
Brian


This is a flaw in how computers handle floating point numbers, not php. As the memory needed to store exact floats to any useful precision would quickly get out of control, floats are handled inprecisely. As a result, you should never test for equality with a float, but rather check if the float is within a certain range of the desired number.


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

http://www.smempire.org

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux