From 1726d23a44ce5b14396d1f186d6ae19e59036854 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 4 Aug 1988 11:17:27 +0000 Subject: [PATCH] problem fixed: number of digits displayed and/or format was sometimes wrong --- lang/cem/libcc/gen/gcvt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lang/cem/libcc/gen/gcvt.c b/lang/cem/libcc/gen/gcvt.c index bd7e55d7d..f5c9f980f 100644 --- a/lang/cem/libcc/gen/gcvt.c +++ b/lang/cem/libcc/gen/gcvt.c @@ -8,22 +8,23 @@ char * gcvt(value, ndigit, buf) double value; char *buf; - register int ndigit; + int ndigit; { int sign, dp; register char *s1, *s2; register int i; + register int nndigit = ndigit; s1 = ecvt(value, ndigit, &dp, &sign); s2 = buf; if (sign) *s2++ = '-'; - for (i = ndigit - 1; i > 0 && s1[i] == '0'; i--) ndigit--; - if (dp - ndigit > NDIGINEXP(dp) + 2 || dp < -NDIGINEXP(dp) - 1) { + for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--) nndigit--; + if (dp > ndigit || dp < -(NDIGINEXP(dp)+1)) { /* Use E format, otherwise we need too many '0''s */ dp--; *s2++ = *s1++; *s2++ = '.'; - while (--ndigit > 0) *s2++ = *s1++; + while (--nndigit > 0) *s2++ = *s1++; *s2++ = 'e'; if (dp < 0) { *s2++ = '-'; @@ -48,7 +49,7 @@ gcvt(value, ndigit, buf) *s2++ = '0'; } } - for (i = 1; i <= ndigit; i++) { + for (i = 1; i <= nndigit; i++) { *s2++ = *s1++; if (i == dp) *s2++ = '.'; }