Fix formatBitrate behavior on Mac OS X
authorAntoine Musso <hashar@users.mediawiki.org>
Fri, 6 Jan 2012 21:49:55 +0000 (21:49 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Fri, 6 Jan 2012 21:49:55 +0000 (21:49 +0000)
commitc6fc4a01b8c3962ff45c3072df164c710986864a
tree065bd05f25487978362e3ca8c73bcd9645ce7959
parent68f79fb6711a830be8551607f33e64ebc7dfe1fc
Fix formatBitrate behavior on Mac OS X

Language::formatBitrate() uses log10() to makes a long number human readeable.
There is a nasty rounding error on Mac OS X for log10():

 log10(pow(10,15)) => gives 15

 floor( log10(pow(10,15)) ) => gives 14 (should be 15)

The end result is that pow(10,15) is formatted as 1,000Tbps instead of 1Pbps

log( $foo, 10) does not suffer from this:

 php -r 'print floor(log(pow(10,15),10)) ."\n";'

PHP Version used:

 $ php -v
 PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep  8 2011 19:34:00)
 Copyright (c) 1997-2011 The PHP Group
 Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
     with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans
 $

TEST PLAN:

BEFORE
======

$ php phpunit.php ./languages/LanguageTest.php
PHPUnit 3.6.3 by Sebastian Bergmann.

...............................................................  63 / 170 ( 37%)
............................................................... 126 / 170 ( 74%)
.......................................F....

Time: 2 seconds, Memory: 32.25Mb

There was 1 failure:

1) LanguageTest::testFormatBitrate with data set #5 (1000000000000000, '1Pbps', '1 petabit per second')
formatBitrate('1000000000000000'): 1 petabit per second
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'1Pbps'
+'1,000Tbps'

FAILURES!
Tests: 170, Assertions: 174, Failures: 1.

AFTER
=====

PHPUnit 3.6.3 by Sebastian Bergmann.

...............................................................  63 / 170 ( 37%)
............................................................... 126 / 170 ( 74%)
............................................

Time: 1 second, Memory: 32.25Mb

OK (170 tests, 174 assertions)
languages/Language.php