Avoid a round() bug that occurs due to over optimization of C code by gcc.

This bug was confirmed across multiple systems with gcc 2.95.3 & 3.X+
This commit is contained in:
Ilia Alshanetsky 2003-08-08 23:40:44 +00:00
parent 4ea2599301
commit 370ea1c82f

View File

@ -32,6 +32,8 @@
#define M_PI 3.14159265358979323846
#endif
#define PHP_ROUND_FUZZ 0.50000000001
/* {{{ proto int abs(int number)
Return the absolute value of the number */
@ -143,9 +145,9 @@ PHP_FUNCTION(round)
return_val *= f;
if (return_val >= 0.0)
return_val = floor(return_val + 0.5);
return_val = floor(return_val + PHP_ROUND_FUZZ);
else
return_val = ceil(return_val - 0.5);
return_val = ceil(return_val - PHP_ROUND_FUZZ);
return_val /= f;
RETURN_DOUBLE(return_val);