From: Antoine Musso Date: Fri, 6 Jan 2012 21:49:55 +0000 (+0000) Subject: Fix formatBitrate behavior on Mac OS X X-Git-Tag: 1.31.0-rc.0~25464 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=c6fc4a01b8c3962ff45c3072df164c710986864a;p=lhc%2Fweb%2Fwiklou.git 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) --- diff --git a/languages/Language.php b/languages/Language.php index 56367dbf7a..71e12abe8e 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3820,7 +3820,7 @@ class Language { if ( $bps <= 0 ) { return str_replace( '$1', $this->formatNum( $bps ), $this->getMessageFromDB( 'bitrate-bits' ) ); } - $unitIndex = (int)floor( log10( $bps ) / 3 ); + $unitIndex = (int)floor( log( $bps, 10 ) / 3 ); $mantissa = $bps / pow( 1000, $unitIndex ); $maxIndex = count( $units ) - 1;