From:             rgonzalez at gnt dot cc
Operating system: Linux Slackware 10.2
PHP version:      5.2.2
PHP Bug Type:     *Math Functions
Bug description:  Weird results from floor after compiling with pentium4 
optimizations

Description:
------------
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

I needed to cast (int)floor to get the right result. I recompiled with
CFLAGS="-O2 -march=i686 -mcpu=i686" and the problem was solved. I've
compiled 5.2.2 with nocona optimizations without problems in other
machines.

Software:

PHP 5.2.2
GCC 3.2.2


Reproduce code:
---------------
<?php

$nt = 100;
$promrow2['uni_gifts'] = 1;
$promrow2['unidades'] = 10;
$calc_cnt=floor(($nt*$promrow2['uni_gifts'])/$promrow2['unidades']);

print $calc_cnt;

?>


Expected result:
----------------
10

Actual result:
--------------
:.0000000001

-- 
Edit bug report at http://bugs.php.net/?id=41328&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41328&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41328&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41328&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41328&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41328&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41328&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41328&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41328&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41328&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41328&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41328&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41328&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41328&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41328&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41328&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41328&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41328&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41328&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41328&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41328&r=mysqlcfg

Reply via email to