Re: Re: Math patches

From: Date: Thu, 04 Dec 2003 22:16:17 +0000
Subject: Re: Re: Math patches
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969357194@lists.php.net to get a copy of this message
Hi all, --- Mehdi Achour <didou@php.net> wrote: > > Hello! > Hi Jakub ;) [...snip...] > > round: in fact, this function doesn't round halves > to the nearest even value as stated > > didn't verify it, but someone else will speak if you > are wrong :) Hmm, indeed that function in the released versions of PHP does round up always. Trying the following code: for ($i=0; $i < 1; $i += 0.1) { echo (10 + $i)." --> ".round(10 + $i)."\n"; } You will see that any value >= 10.5 is rounded to 11 (tried w/ 4.3.0 on a Solaris box and 4.3.3 on a Linux box). Adding the second parameter which makes it work to generate floating point results, does the same rounding up: for ($i=0; $i < 0.1; $i += 0.01) { echo (10.1 + $i)." --> ".round(10.1 + $i,1)."\n"; } And you'll quickly notice the trend. The examples in the manual entry do need to be changed, the output of round(5.045, 2) is 5.05 not 5.04 Seems like Derick added that caution last June 16 (rev 1.4 of round.xml). See that at: http://cvs.php.net/annotate.php/phpdoc/en/reference/math/functions/round.xml?rev=1.5 or http://bonsai.php.net/bonsai/cvsblame.cgi?file=phpdoc/en/reference/math/functions/round.xml&rev=&root=/repository Last changes on round() in php-src/ext/standard/math.c are from August and November this year: ... ---------------------------- revision 1.109 date: 2003/11/18 02:50:40; author: iliaa; state: Exp; lines: +18 -11 Fixed Bug #25694 (round() and number_format() give inconsistent results). ---------------------------- ... ---------------------------- revision 1.105 date: 2003/08/08 23:40:44; author: iliaa; state: Exp; lines: +5 -3 Avoid a round() bug that occurs due to over optimization of C code by gcc. This bug was confirmed across multiple systems with gcc 2.95.3 & 3.X+ ---------------------------- Ilia's change makes it behave as documented, although the current release doesn't. Bottomline, fix the example and change the comment to say that it describes future behavior not current behavior, and as such should be a warning for people relying on the rounding up behavior. See the diff at: http://cvs.php.net/diff.php/php-src/ext/standard/math.c?r1=1.97.2.7&r2=1.97.2.8&ty=h for the definition of the PHP_ROUND_WITH_FUZZ macro. > > no news with your CVS account request ? > > Oh yes, something else : I'm not sure but if you > name your patch > "stg.txt" it will be displayed inline with your > message in most mail > reader (mine, btw ;)). It will be a little be handy > to quick view it. > > Keep the good work ! > > didou ===== --- Jesus M. Castagnetto <jmcastagnetto@php.net> __________________________________ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/

« previous php.doc (#969357194) next »