Comment: | 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) |