Просмотр исходного кода

floatscan: fix incorrect count of leading nonzero digits

this off-by-one error was causing values with just one digit past the
decimal point to be treated by the integer case. in many cases it
would yield the correct result, but if expressions are evaluated in
excess precision, double rounding may occur.
Rich Felker 13 лет назад
Родитель
Сommit
2ac580fdfe
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      src/internal/floatscan.c

+ 1 - 1
src/internal/floatscan.c

@@ -81,8 +81,8 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
 			if (lrp!=-1) break;
 			if (lrp!=-1) break;
 			lrp = dc;
 			lrp = dc;
 		} else if (k < KMAX-2) {
 		} else if (k < KMAX-2) {
-			if (c!='0') lnz = dc;
 			dc++;
 			dc++;
+			if (c!='0') lnz = dc;
 			if (j) x[k] = x[k]*10 + c-'0';
 			if (j) x[k] = x[k]*10 + c-'0';
 			else x[k] = c-'0';
 			else x[k] = c-'0';
 			if (++j==9) {
 			if (++j==9) {