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

Issue Type: Unit Tests: Problem Created: 2009-03-13T07:52:21.000+0000 Last Updated: 2009-03-26T13:29:55.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Alexander Veremyev (alexander) Assignee: Thomas Weidner (thomas) Tags: - Zend_Locale

Related issues: Attachments:


{panel} 1) testRound(Zend_Locale_MathTest) 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.

Test this:

<pre class="highlight">
// returns -2.3283064365387E-10
echo round(1241757, -3) - 1242000;

Posted by Thomas Weidner (thomas) on 2009-03-13T10:46:06.000+0000

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.

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

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.