From: Ilia Alshanetsky Date: Fri, 8 Aug 2003 23:42:10 +0000 (+0000) Subject: MFH: Avoid a round() bug that occurs due to over optimization of C code by X-Git-Tag: php-4.3.3RC4~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2302046dd38ada576f764e98fc12801e7f3c440;p=php MFH: Avoid a round() bug that occurs due to over optimization of C code by gcc. --- diff --git a/ext/standard/math.c b/ext/standard/math.c index 137b228d96..1b93b6fd0f 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -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);