Weird results with floor compiling with -march=pentium4 -mcpu=pentium4
| From: | Rodolfo Gonzalez Gonzalez | Date: | Tue, 08 May 2007 17:24:42 +0000 |
| Subject: | Weird results with floor compiling with -march=pentium4 -mcpu=pentium4 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-254561@lists.php.net to get a copy of this message | ||
Hi,
Just for the record. I compiled PHP 5.2.2 with CFLAGS="-O2 -march=pentium4 -mcpu=pentium4", as usual (I've done so with all the 5.x.x series, and the proc is a Pentium 4, of course) and a customer complained about weird results in one of his scripts. I isolated the problem to be related to the floor function. The problem was that it returned weird results. Sample script:
<?php
$nt = 100;
$promrow2['uni_gifts'] = 1;
$promrow2['unidades'] = 10;
$calc_cnt=floor(($nt*$promrow2['uni_gifts'])/$promrow2['unidades']);
print $calc_cnt;
?>
printed :.0000000001
Casting to integer the value returned by floor solved the problem. I recompiled with CFLAGS="-O2 -march=i686 -mcpu=i686" and the problem was solved too. I've compiled 5.2.2 with nocona optimizations without problems in other machines, so I don't consider this a normal behavior. But report submited. Has anyone faced the same problem?.
Software:
PHP 5.2.2
GCC 3.2.2
Regards,
Rodolfo.