php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41328 Weird results from floor after compiling with pentium4 optimizations
Submitted: 2007-05-08 17:26 UTC Modified: 2007-05-16 01:00 UTC
From: rgonzalez at gnt dot cc Assigned:
Status: No Feedback Package: *Math Functions
PHP Version: 5.2.2 OS: Linux Slackware 10.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rgonzalez at gnt dot cc
New email:
PHP Version: OS:

 

 [2007-05-08 17:26 UTC] rgonzalez at gnt dot cc
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-08 17:44 UTC] tony2001@php.net
Try newer GCC first.
 [2007-05-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Mar 11 06:01:29 2025 UTC