#42294 [Opn->Fbk]: round will not use PHP_ROUND_FUZZ on 64bit CPUs

From: Date: Wed, 15 Aug 2007 08:47:38 +0000
Subject: #42294 [Opn->Fbk]: round will not use PHP_ROUND_FUZZ on 64bit CPUs
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116139@lists.php.net to get a copy of this message
 ID:               42294
 Updated by:       jani@php.net
 Reported By:      oliver at teqneers dot de
-Status:           Open
+Status:           Feedback
 Bug Type:         *Configuration Issues
 Operating System: OpenSuSE 10.2
 PHP Version:      5.2.4RC1
 New Comment:

Can you please provide a short PHP code example which fails because of
this..?


Previous Comments:
------------------------------------------------------------------------

[2007-08-14 10:46:19] oliver at teqneers dot de

Description:
------------
Because of the nature of floats to be not exact enough in binary
system, PHP uses a kind of fuzzy login to round more precisely turning
on PHP_ROUND_FUZZ in some cases.

The problem is the "configure" check. The check does not work for AMD
nor INTEL 64bit CPUs.

The number to test against is not sufficient. So maybe it is possible
to add or change it???

Reproduce code:
---------------
#include <math.h>
  /* keep this out-of-line to prevent use of gcc inline floor() */
  double somefn(double n) {
    return floor(n*pow(10,2) + 0.5);
  }
  int main() {
    return somefn(0.045)/10.0 != 0.5;
  }

this will return 1 on a 32bit but 0 on a 64bit engine.

Expected result:
----------------
it should also fail on a 64bit and return 1. The following code would
actually work on 64bit, because it will test 0.45 as well as 0.285:


#include <math.h>
  /* keep this out-of-line to prevent use of gcc inline floor() */
  double somefn(double n) {
    return floor(n*pow(10,2) + 0.5);
  }
  int main() {
    return (somefn(0.285)/100.0 != 0.29) || (somefn(0.045) / 10.0 !=
0.5);
  }

Actual result:
--------------
Instead of using the fuzzy round, PHP just takes 0.5 and
adds/substracts it from the given float (math.c)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42294&edit=1


Thread (15 messages)

« previous php.bugs (#116139) next »