Note: issues are now on GitHub; see the Overview for more
Failed asserting that
Posted by Alexander Veremyev (alexander) on 2009-03-13T08:00:38.000+0000
Problem is actually caused by nature of floating point arithmetic: round(1241757, -3) != 1242000
that's caused by floating point numbers internal representation.
Even (string)round(1241757, -3) returns '1242000', round(1241757, -3) is not equal to 1242000.
// returns -2.3283064365387E-10
echo round(1241757, -3) - 1242000;
Posted by Thomas Weidner (thomas) on 2009-03-13T10:46:06.000+0000
I am confused. How is it possible that this failure exists now and not before ?
The only one who made changes to Zend_Locale_Math was you (without informing me).
And this test exist without changes since more than one year.
Posted by Alexander Veremyev (alexander) on 2009-03-13T11:00:56.000+0000
I've just added new environment for testing:
Ubuntu server with Zend Server installation, so it differs from environment I used before (and also still using now in addition to this new).
Zend Server has bcmath extension disabled. that also may affect result.
But actualy the core of the problem is in the fact that it's not correct to compare floats using comparison operator.
Internal floats representation and operations results may vary depending on syste/php version.
Posted by Thomas Weidner (thomas) on 2009-03-13T11:18:28.000+0000
Ok... the problem is not the calculation... it is correct.
According to the changed environment, Ubuntu does a automatic conversion from string to double when the value is small enough. This could also effect 64bit environments.
Still, as the calculation returns the same result, only the test is not correct.
Instead of Equal, Same or Contain should be used.
Posted by Alexander Veremyev (alexander) on 2009-03-13T11:22:31.000+0000
I think some form of abs($expected - $actual) < $delta should be used there.
Posted by Thomas Weidner (thomas) on 2009-03-13T11:57:10.000+0000
With some of the last releases of phpunit a delta was added to equals for environment independent float testing. I added it with r14308 and it works under my environments.
Please check for yours.
Posted by Thomas Weidner (thomas) on 2009-03-26T13:29:46.000+0000
Closing due to non-negative response