Issues

ZF-6022: testRound(Zend_Locale_MathTest) unit tests failure (bcmath is disabled)

Description

{panel} 1) testRound(Zend_Locale_MathTest) Failed asserting that

Comments

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.

Test this:


// returns -2.3283064365387E-10
echo round(1241757, -3) - 1242000;

Alex: 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.

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.

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.

Exactly.

I think some form of abs($expected - $actual) < $delta should be used there.

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.

Closing due to non-negative response