From: Jeroen van Wolffelaar Date: Sun, 5 Aug 2001 20:27:03 +0000 (+0000) Subject: Bugfix in abs(), abs(LONG_MIN) was bogus X-Git-Tag: PRE_ENGINE2_SPLIT~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec140f4f67f48ee1f08d1453e38026c2c789c4ad;p=php Bugfix in abs(), abs(LONG_MIN) was bogus --- diff --git a/ext/standard/math.c b/ext/standard/math.c index 89c529623c..dc5b427967 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -49,7 +49,11 @@ PHP_FUNCTION(abs) if (Z_TYPE_PP(value) == IS_DOUBLE) { RETURN_DOUBLE(fabs(Z_DVAL_PP(value))); } else if (Z_TYPE_PP(value) == IS_LONG) { - RETURN_LONG(Z_LVAL_PP(value) < 0 ? -Z_LVAL_PP(value) : Z_LVAL_PP(value)); + if (Z_LVAL_PP(value) == LONG_MIN) { + RETURN_DOUBLE(-(double)LONG_MIN); + } else { + RETURN_LONG(Z_LVAL_PP(value) < 0 ? -Z_LVAL_PP(value) : Z_LVAL_PP(value)); + } } RETURN_FALSE; @@ -466,19 +470,10 @@ PHP_FUNCTION(pow) } case 1: RETURN_LONG(1); - case LONG_MIN: /* special case since -LONG_MIN == 0 */ - /* lexp != 0, and only lexp==1 is LONG, DOUBLE otherwise */ - if (lexp == 1) { - RETURN_LONG(LONG_MIN); - } else { - dval = exp(log(-(double)LONG_MIN) * (double)lexp); - RETURN_DOUBLE(lexp&1 ? -dval : dval); - } default: /* abs(lbase) > 1 */ - dval = exp(log((double) (lbase>0?lbase:-lbase)) * + dval = exp(log(lbase>0? (double)lbase : -(double)lbase ) * (double) lexp); - /* long result = 1; */ if (lexp < 0 || dval > (double) LONG_MAX) { /* 1/n ( abs(n) > 1 ) || overflow */ RETURN_DOUBLE(((lexp & 1) && lbase<0) ? -dval : dval);