ID:               42294
 User updated by:  oliver at teqneers dot de
 Reported By:      oliver at teqneers dot de
-Status:           Feedback
+Status:           Open
 Bug Type:         *Configuration Issues
 Operating System: OpenSuSE 10.2
 PHP Version:      5.2.4RC1
 New Comment:

you might use a windows machine? there the fuzzy seems to be always
turned off (I don't know why though???). 

math.c:
-------
#ifndef PHP_ROUND_FUZZ
# ifndef PHP_WIN32
#  define PHP_ROUND_FUZZ 0.50000000001
# else
#  define PHP_ROUND_FUZZ 0.5
# endif
#endif




But I have to admit, that I forgot to switch to the php5 versions on
our 32bit server. So on all our PHP4 versions with 32bit, round seems to
work as mathematically expected. Sorry for that. 

BUT still the result could be correct with PHP_ROUND_FUZZ on, like it
did with PHP4. I compiled the latest PHP5 (5.2.4RC1) and changed the
configure check to be more precise. After that the round was working
much better, than it did before. My current result with the patched
configure script is:
0.285 - 0.29
1.285 - 1.29 
1.255 - 1.26

I mean, why is the FUZZ implemented and not used???


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

[2007-08-16 10:30:57] [EMAIL PROTECTED]

Output for me on a 32bit system:
0.285 - 0.28
1.285 - 1.29
1.255 - 1.25


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

[2007-08-16 10:29:52] [EMAIL PROTECTED]

Those results you get are NOT incorrect. If you round using 2 decimals,
of course that's what you get.

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

[2007-08-15 11:25:09] oliver at teqneers dot de

this is an example of the comment block of the round documentation
(http://de.php.net/manual/en/function.round.php):

<?php

printf("0.285 - %s <br> ",round(0.285,2));      
// incorrect result 0.28

printf("1.285 - %s <br> ",round(1.285,2));      
// correct result 1.29

printf("1.255 - %s <br><br>",round(1.255,2));   
// incorrect result 1.25

?>

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

[2007-08-15 08:47:36] [EMAIL PROTECTED]

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

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

[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

Reply via email to