Bug 469397 - (0.5).toFixed(0) is 0, should be 1. r=bz,mrbkap
authorBrian Crowder <crowder@fiverocks.com>
Sat, 07 Feb 2009 12:31:10 +0100
changeset 24730 98fe21ddf417f997d6c17b2024f58526350ae791
parent 24729 6ebf4afe67d22879596af8a2e35f5a4df43eb331
child 24731 ca6426f959b380c30e1bc16ca14646daa5b8f38f
push idunknown
push userunknown
push dateunknown
reviewersbz, mrbkap
bugs469397
milestone1.9.2a1pre
Bug 469397 - (0.5).toFixed(0) is 0, should be 1. r=bz,mrbkap
js/src/dtoa.c
--- a/js/src/dtoa.c
+++ b/js/src/dtoa.c
@@ -2985,17 +2985,17 @@ dtoa
 
 	/* Do we have a "small" integer? */
 
 	if (be >= 0 && k <= Int_max) {
 		/* Yes. */
 		ds = tens[k];
 		if (ndigits < 0 && ilim <= 0) {
 			S = mhi = 0;
-			if (ilim < 0 || dval(d) <= 5*ds)
+			if (ilim < 0 || dval(d) < 5*ds)
 				goto no_digits;
 			goto one_digit;
 			}
 		for(i = 1;; i++, dval(d) *= 10.) {
 			L = (Long)(dval(d) / ds);
 			dval(d) -= L*ds;
 #ifdef Check_FLT_ROUNDS
 			/* If FLT_ROUNDS == 2, L will usually be high by 1 */
@@ -3132,17 +3132,17 @@ dtoa
 			k--;
 			b = multadd(b, 10, 0);	/* we botched the k estimate */
 			if (leftright)
 				mhi = multadd(mhi, 10, 0);
 			ilim = ilim1;
 			}
 		}
 	if (ilim <= 0 && (mode == 3 || mode == 5)) {
-		if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+		if (ilim < 0 || cmp(b,S = multadd(S,5,0)) < 0) {
 			/* no digits, fcvt style */
  no_digits:
 			/* MOZILLA CHANGE: Always return a non-empty string. */
 			*s++ = '0';
 			k = 0;
 			goto ret;
 			}
  one_digit:
@@ -3268,17 +3268,17 @@ dtoa
 #ifdef Honor_FLT_ROUNDS
 	switch(rounding) {
 	  case 0: goto trimzeros;
 	  case 2: goto roundoff;
 	  }
 #endif
 	b = lshift(b, 1);
 	j = cmp(b, S);
-	if (j > 0 || (j == 0 && dig & 1)) {
+	if (j >= 0) {  /* ECMA compatible rounding needed by Spidermonkey */
  roundoff:
 		while(*--s == '9')
 			if (s == s0) {
 				k++;
 				*s++ = '1';
 				goto ret;
 				}
 		++*s++;