Deleted Added
full compact
gdtoa.c (187808) gdtoa.c (219557)
1/****************************************************************
2
3The author of this software is David M. Gay.
4
5Copyright (C) 1998, 1999 by Lucent Technologies
6All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and

--- 109 unchanged lines hidden (view full) ---

118 (FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)
119#endif
120{
121 /* Arguments ndigits and decpt are similar to the second and third
122 arguments of ecvt and fcvt; trailing zeros are suppressed from
123 the returned string. If not null, *rve is set to point
124 to the end of the return value. If d is +-Infinity or NaN,
125 then *decpt is set to 9999.
1/****************************************************************
2
3The author of this software is David M. Gay.
4
5Copyright (C) 1998, 1999 by Lucent Technologies
6All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and

--- 109 unchanged lines hidden (view full) ---

118 (FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)
119#endif
120{
121 /* Arguments ndigits and decpt are similar to the second and third
122 arguments of ecvt and fcvt; trailing zeros are suppressed from
123 the returned string. If not null, *rve is set to point
124 to the end of the return value. If d is +-Infinity or NaN,
125 then *decpt is set to 9999.
126 be = exponent: value = (integer represented by bits) * (2 to the power of be).
126
127 mode:
128 0 ==> shortest string that yields d when read in
129 and rounded to nearest.
130 1 ==> like 0, but with Steele & White stopping rule;
131 e.g. with IEEE P754 arithmetic , mode 0 gives
132 1e23 whereas mode 1 gives 9.999999999999999e22.
133 2 ==> max(1,ndigits) significant digits. This gives a

--- 18 unchanged lines hidden (view full) ---

152 to hold the suppressed trailing zeros.
153 */
154
155 int bbits, b2, b5, be0, dig, i, ieps, ilim, ilim0, ilim1, inex;
156 int j, j1, k, k0, k_check, kind, leftright, m2, m5, nbits;
157 int rdir, s2, s5, spec_case, try_quick;
158 Long L;
159 Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S;
127
128 mode:
129 0 ==> shortest string that yields d when read in
130 and rounded to nearest.
131 1 ==> like 0, but with Steele & White stopping rule;
132 e.g. with IEEE P754 arithmetic , mode 0 gives
133 1e23 whereas mode 1 gives 9.999999999999999e22.
134 2 ==> max(1,ndigits) significant digits. This gives a

--- 18 unchanged lines hidden (view full) ---

153 to hold the suppressed trailing zeros.
154 */
155
156 int bbits, b2, b5, be0, dig, i, ieps, ilim, ilim0, ilim1, inex;
157 int j, j1, k, k0, k_check, kind, leftright, m2, m5, nbits;
158 int rdir, s2, s5, spec_case, try_quick;
159 Long L;
160 Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S;
160 double d, d2, ds, eps;
161 double d2, ds;
161 char *s, *s0;
162 char *s, *s0;
163 U d, eps;
162
163#ifndef MULTIPLE_THREADS
164 if (dtoa_result) {
165 freedtoa(dtoa_result);
166 dtoa_result = 0;
167 }
168#endif
169 inex = 0;

--- 22 unchanged lines hidden (view full) ---

192 }
193 if (!b->wds) {
194 Bfree(b);
195 ret_zero:
196 *decpt = 1;
197 return nrv_alloc("0", rve, 1);
198 }
199
164
165#ifndef MULTIPLE_THREADS
166 if (dtoa_result) {
167 freedtoa(dtoa_result);
168 dtoa_result = 0;
169 }
170#endif
171 inex = 0;

--- 22 unchanged lines hidden (view full) ---

194 }
195 if (!b->wds) {
196 Bfree(b);
197 ret_zero:
198 *decpt = 1;
199 return nrv_alloc("0", rve, 1);
200 }
201
200 dval(d) = b2d(b, &i);
202 dval(&d) = b2d(b, &i);
201 i = be + bbits - 1;
203 i = be + bbits - 1;
202 word0(d) &= Frac_mask1;
203 word0(d) |= Exp_11;
204 word0(&d) &= Frac_mask1;
205 word0(&d) |= Exp_11;
204#ifdef IBM
206#ifdef IBM
205 if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0)
206 dval(d) /= 1 << j;
207 if ( (j = 11 - hi0bits(word0(&d) & Frac_mask)) !=0)
208 dval(&d) /= 1 << j;
207#endif
208
209 /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
210 * log10(x) = log(x) / log(10)
211 * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
209#endif
210
211 /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
212 * log10(x) = log(x) / log(10)
213 * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
212 * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
214 * log10(&d) = (i-Bias)*log(2)/log(10) + log10(d2)
213 *
215 *
214 * This suggests computing an approximation k to log10(d) by
216 * This suggests computing an approximation k to log10(&d) by
215 *
216 * k = (i - Bias)*0.301029995663981
217 * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
218 *
219 * We want k to be too large rather than too small.
220 * The error in the first-order Taylor series approximation
221 * is in our favor, so we just round up the constant enough
222 * to compensate for any error in the multiplication of
223 * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
224 * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
225 * adding 1e-13 to the constant term more than suffices.
226 * Hence we adjust the constant term to 0.1760912590558.
227 * (We could get a more accurate k by invoking log10,
228 * but this is probably not worthwhile.)
229 */
230#ifdef IBM
231 i <<= 2;
232 i += j;
233#endif
217 *
218 * k = (i - Bias)*0.301029995663981
219 * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
220 *
221 * We want k to be too large rather than too small.
222 * The error in the first-order Taylor series approximation
223 * is in our favor, so we just round up the constant enough
224 * to compensate for any error in the multiplication of
225 * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
226 * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
227 * adding 1e-13 to the constant term more than suffices.
228 * Hence we adjust the constant term to 0.1760912590558.
229 * (We could get a more accurate k by invoking log10,
230 * but this is probably not worthwhile.)
231 */
232#ifdef IBM
233 i <<= 2;
234 i += j;
235#endif
234 ds = (dval(d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
236 ds = (dval(&d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
235
236 /* correct assumption about exponent range */
237 if ((j = i) < 0)
238 j = -j;
239 if ((j -= 1077) > 0)
240 ds += j * 7e-17;
241
242 k = (int)ds;
243 if (ds < 0. && ds != k)
244 k--; /* want k = floor(ds) */
245 k_check = 1;
246#ifdef IBM
247 j = be + bbits - 1;
248 if ( (j1 = j & 3) !=0)
237
238 /* correct assumption about exponent range */
239 if ((j = i) < 0)
240 j = -j;
241 if ((j -= 1077) > 0)
242 ds += j * 7e-17;
243
244 k = (int)ds;
245 if (ds < 0. && ds != k)
246 k--; /* want k = floor(ds) */
247 k_check = 1;
248#ifdef IBM
249 j = be + bbits - 1;
250 if ( (j1 = j & 3) !=0)
249 dval(d) *= 1 << j1;
250 word0(d) += j << Exp_shift - 2 & Exp_mask;
251 dval(&d) *= 1 << j1;
252 word0(&d) += j << Exp_shift - 2 & Exp_mask;
251#else
253#else
252 word0(d) += (be + bbits - 1) << Exp_shift;
254 word0(&d) += (be + bbits - 1) << Exp_shift;
253#endif
254 if (k >= 0 && k <= Ten_pmax) {
255#endif
256 if (k >= 0 && k <= Ten_pmax) {
255 if (dval(d) < tens[k])
257 if (dval(&d) < tens[k])
256 k--;
257 k_check = 0;
258 }
259 j = bbits - i - 1;
260 if (j >= 0) {
261 b2 = 0;
262 s2 = j;
263 }

--- 13 unchanged lines hidden (view full) ---

277 }
278 if (mode < 0 || mode > 9)
279 mode = 0;
280 try_quick = 1;
281 if (mode > 5) {
282 mode -= 4;
283 try_quick = 0;
284 }
258 k--;
259 k_check = 0;
260 }
261 j = bbits - i - 1;
262 if (j >= 0) {
263 b2 = 0;
264 s2 = j;
265 }

--- 13 unchanged lines hidden (view full) ---

279 }
280 if (mode < 0 || mode > 9)
281 mode = 0;
282 try_quick = 1;
283 if (mode > 5) {
284 mode -= 4;
285 try_quick = 0;
286 }
287 else if (i >= -4 - Emin || i < Emin)
288 try_quick = 0;
285 leftright = 1;
289 leftright = 1;
290 ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */
291 /* silence erroneous "gcc -Wall" warning. */
286 switch(mode) {
287 case 0:
288 case 1:
292 switch(mode) {
293 case 0:
294 case 1:
289 ilim = ilim1 = -1;
290 i = (int)(nbits * .30103) + 3;
291 ndigits = 0;
292 break;
293 case 2:
294 leftright = 0;
295 /* no break */
296 case 4:
297 if (ndigits <= 0)

--- 25 unchanged lines hidden (view full) ---

323#ifndef IMPRECISE_INEXACT
324 && k == 0
325#endif
326 ) {
327
328 /* Try to get by with floating-point arithmetic. */
329
330 i = 0;
295 i = (int)(nbits * .30103) + 3;
296 ndigits = 0;
297 break;
298 case 2:
299 leftright = 0;
300 /* no break */
301 case 4:
302 if (ndigits <= 0)

--- 25 unchanged lines hidden (view full) ---

328#ifndef IMPRECISE_INEXACT
329 && k == 0
330#endif
331 ) {
332
333 /* Try to get by with floating-point arithmetic. */
334
335 i = 0;
331 d2 = dval(d);
336 d2 = dval(&d);
332#ifdef IBM
337#ifdef IBM
333 if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0)
334 dval(d) /= 1 << j;
338 if ( (j = 11 - hi0bits(word0(&d) & Frac_mask)) !=0)
339 dval(&d) /= 1 << j;
335#endif
336 k0 = k;
337 ilim0 = ilim;
338 ieps = 2; /* conservative */
339 if (k > 0) {
340 ds = tens[k&0xf];
341 j = k >> 4;
342 if (j & Bletch) {
343 /* prevent overflows */
344 j &= Bletch - 1;
340#endif
341 k0 = k;
342 ilim0 = ilim;
343 ieps = 2; /* conservative */
344 if (k > 0) {
345 ds = tens[k&0xf];
346 j = k >> 4;
347 if (j & Bletch) {
348 /* prevent overflows */
349 j &= Bletch - 1;
345 dval(d) /= bigtens[n_bigtens-1];
350 dval(&d) /= bigtens[n_bigtens-1];
346 ieps++;
347 }
348 for(; j; j >>= 1, i++)
349 if (j & 1) {
350 ieps++;
351 ds *= bigtens[i];
352 }
353 }
354 else {
355 ds = 1.;
356 if ( (j1 = -k) !=0) {
351 ieps++;
352 }
353 for(; j; j >>= 1, i++)
354 if (j & 1) {
355 ieps++;
356 ds *= bigtens[i];
357 }
358 }
359 else {
360 ds = 1.;
361 if ( (j1 = -k) !=0) {
357 dval(d) *= tens[j1 & 0xf];
362 dval(&d) *= tens[j1 & 0xf];
358 for(j = j1 >> 4; j; j >>= 1, i++)
359 if (j & 1) {
360 ieps++;
363 for(j = j1 >> 4; j; j >>= 1, i++)
364 if (j & 1) {
365 ieps++;
361 dval(d) *= bigtens[i];
366 dval(&d) *= bigtens[i];
362 }
363 }
364 }
367 }
368 }
369 }
365 if (k_check && dval(d) < 1. && ilim > 0) {
370 if (k_check && dval(&d) < 1. && ilim > 0) {
366 if (ilim1 <= 0)
367 goto fast_failed;
368 ilim = ilim1;
369 k--;
371 if (ilim1 <= 0)
372 goto fast_failed;
373 ilim = ilim1;
374 k--;
370 dval(d) *= 10.;
375 dval(&d) *= 10.;
371 ieps++;
372 }
376 ieps++;
377 }
373 dval(eps) = ieps*dval(d) + 7.;
374 word0(eps) -= (P-1)*Exp_msk1;
378 dval(&eps) = ieps*dval(&d) + 7.;
379 word0(&eps) -= (P-1)*Exp_msk1;
375 if (ilim == 0) {
376 S = mhi = 0;
380 if (ilim == 0) {
381 S = mhi = 0;
377 dval(d) -= 5.;
378 if (dval(d) > dval(eps))
382 dval(&d) -= 5.;
383 if (dval(&d) > dval(&eps))
379 goto one_digit;
384 goto one_digit;
380 if (dval(d) < -dval(eps))
385 if (dval(&d) < -dval(&eps))
381 goto no_digits;
382 goto fast_failed;
383 }
384#ifndef No_leftright
385 if (leftright) {
386 /* Use Steele & White method of only
387 * generating digits needed.
388 */
386 goto no_digits;
387 goto fast_failed;
388 }
389#ifndef No_leftright
390 if (leftright) {
391 /* Use Steele & White method of only
392 * generating digits needed.
393 */
389 dval(eps) = ds*0.5/tens[ilim-1] - dval(eps);
394 dval(&eps) = ds*0.5/tens[ilim-1] - dval(&eps);
390 for(i = 0;;) {
395 for(i = 0;;) {
391 L = (Long)(dval(d)/ds);
392 dval(d) -= L*ds;
396 L = (Long)(dval(&d)/ds);
397 dval(&d) -= L*ds;
393 *s++ = '0' + (int)L;
398 *s++ = '0' + (int)L;
394 if (dval(d) < dval(eps)) {
395 if (dval(d))
399 if (dval(&d) < dval(&eps)) {
400 if (dval(&d))
396 inex = STRTOG_Inexlo;
397 goto ret1;
398 }
401 inex = STRTOG_Inexlo;
402 goto ret1;
403 }
399 if (ds - dval(d) < dval(eps))
404 if (ds - dval(&d) < dval(&eps))
400 goto bump_up;
401 if (++i >= ilim)
402 break;
405 goto bump_up;
406 if (++i >= ilim)
407 break;
403 dval(eps) *= 10.;
404 dval(d) *= 10.;
408 dval(&eps) *= 10.;
409 dval(&d) *= 10.;
405 }
406 }
407 else {
408#endif
409 /* Generate ilim digits, then fix them up. */
410 }
411 }
412 else {
413#endif
414 /* Generate ilim digits, then fix them up. */
410 dval(eps) *= tens[ilim-1];
411 for(i = 1;; i++, dval(d) *= 10.) {
412 if ( (L = (Long)(dval(d)/ds)) !=0)
413 dval(d) -= L*ds;
415 dval(&eps) *= tens[ilim-1];
416 for(i = 1;; i++, dval(&d) *= 10.) {
417 if ( (L = (Long)(dval(&d)/ds)) !=0)
418 dval(&d) -= L*ds;
414 *s++ = '0' + (int)L;
415 if (i == ilim) {
416 ds *= 0.5;
419 *s++ = '0' + (int)L;
420 if (i == ilim) {
421 ds *= 0.5;
417 if (dval(d) > ds + dval(eps))
422 if (dval(&d) > ds + dval(&eps))
418 goto bump_up;
423 goto bump_up;
419 else if (dval(d) < ds - dval(eps)) {
420 if (dval(d))
424 else if (dval(&d) < ds - dval(&eps)) {
425 if (dval(&d))
421 inex = STRTOG_Inexlo;
422 goto clear_trailing0;
423 }
424 break;
425 }
426 }
427#ifndef No_leftright
428 }
429#endif
430 fast_failed:
431 s = s0;
426 inex = STRTOG_Inexlo;
427 goto clear_trailing0;
428 }
429 break;
430 }
431 }
432#ifndef No_leftright
433 }
434#endif
435 fast_failed:
436 s = s0;
432 dval(d) = d2;
437 dval(&d) = d2;
433 k = k0;
434 ilim = ilim0;
435 }
436
437 /* Do we have a "small" integer? */
438
439 if (be >= 0 && k <= Int_max) {
440 /* Yes. */
441 ds = tens[k];
442 if (ndigits < 0 && ilim <= 0) {
443 S = mhi = 0;
438 k = k0;
439 ilim = ilim0;
440 }
441
442 /* Do we have a "small" integer? */
443
444 if (be >= 0 && k <= Int_max) {
445 /* Yes. */
446 ds = tens[k];
447 if (ndigits < 0 && ilim <= 0) {
448 S = mhi = 0;
444 if (ilim < 0 || dval(d) <= 5*ds)
449 if (ilim < 0 || dval(&d) <= 5*ds)
445 goto no_digits;
446 goto one_digit;
447 }
450 goto no_digits;
451 goto one_digit;
452 }
448 for(i = 1;; i++, dval(d) *= 10.) {
449 L = dval(d) / ds;
450 dval(d) -= L*ds;
453 for(i = 1;; i++, dval(&d) *= 10.) {
454 L = dval(&d) / ds;
455 dval(&d) -= L*ds;
451#ifdef Check_FLT_ROUNDS
452 /* If FLT_ROUNDS == 2, L will usually be high by 1 */
456#ifdef Check_FLT_ROUNDS
457 /* If FLT_ROUNDS == 2, L will usually be high by 1 */
453 if (dval(d) < 0) {
458 if (dval(&d) < 0) {
454 L--;
459 L--;
455 dval(d) += ds;
460 dval(&d) += ds;
456 }
457#endif
458 *s++ = '0' + (int)L;
461 }
462#endif
463 *s++ = '0' + (int)L;
459 if (dval(d) == 0.)
464 if (dval(&d) == 0.)
460 break;
461 if (i == ilim) {
462 if (rdir) {
463 if (rdir == 1)
464 goto bump_up;
465 inex = STRTOG_Inexlo;
466 goto ret1;
467 }
465 break;
466 if (i == ilim) {
467 if (rdir) {
468 if (rdir == 1)
469 goto bump_up;
470 inex = STRTOG_Inexlo;
471 goto ret1;
472 }
468 dval(d) += dval(d);
469 if (dval(d) > ds || dval(d) == ds && L & 1) {
473 dval(&d) += dval(&d);
474#ifdef ROUND_BIASED
475 if (dval(&d) >= ds)
476#else
477 if (dval(&d) > ds || (dval(&d) == ds && L & 1))
478#endif
479 {
470 bump_up:
471 inex = STRTOG_Inexhi;
472 while(*--s == '9')
473 if (s == s0) {
474 k++;
475 *s = '0';
476 break;
477 }

--- 10 unchanged lines hidden (view full) ---

488 }
489 goto ret1;
490 }
491
492 m2 = b2;
493 m5 = b5;
494 mhi = mlo = 0;
495 if (leftright) {
480 bump_up:
481 inex = STRTOG_Inexhi;
482 while(*--s == '9')
483 if (s == s0) {
484 k++;
485 *s = '0';
486 break;
487 }

--- 10 unchanged lines hidden (view full) ---

498 }
499 goto ret1;
500 }
501
502 m2 = b2;
503 m5 = b5;
504 mhi = mlo = 0;
505 if (leftright) {
496 if (mode < 2) {
497 i = nbits - bbits;
498 if (be - i++ < fpi->emin)
499 /* denormal */
500 i = be - fpi->emin + 1;
506 i = nbits - bbits;
507 if (be - i++ < fpi->emin && mode != 3 && mode != 5) {
508 /* denormal */
509 i = be - fpi->emin + 1;
510 if (mode >= 2 && ilim > 0 && ilim < i)
511 goto small_ilim;
501 }
512 }
502 else {
513 else if (mode >= 2) {
514 small_ilim:
503 j = ilim - 1;
504 if (m5 >= j)
505 m5 -= j;
506 else {
507 s5 += j -= m5;
508 b5 += j;
509 m5 = 0;
510 }

--- 44 unchanged lines hidden (view full) ---

555
556 /* Arrange for convenient computation of quotients:
557 * shift left if necessary so divisor has 4 leading 0 bits.
558 *
559 * Perhaps we should just compute leading 28 bits of S once
560 * and for all and pass them and a shift to quorem, so it
561 * can do shifts and ors to compute the numerator for q.
562 */
515 j = ilim - 1;
516 if (m5 >= j)
517 m5 -= j;
518 else {
519 s5 += j -= m5;
520 b5 += j;
521 m5 = 0;
522 }

--- 44 unchanged lines hidden (view full) ---

567
568 /* Arrange for convenient computation of quotients:
569 * shift left if necessary so divisor has 4 leading 0 bits.
570 *
571 * Perhaps we should just compute leading 28 bits of S once
572 * and for all and pass them and a shift to quorem, so it
573 * can do shifts and ors to compute the numerator for q.
574 */
563#ifdef Pack_32
564 if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) !=0)
565 i = 32 - i;
566#else
567 if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) !=0)
568 i = 16 - i;
569#endif
570 if (i > 4) {
571 i -= 4;
572 b2 += i;
573 m2 += i;
574 s2 += i;
575 }
576 else if (i < 4) {
577 i += 28;
578 b2 += i;
579 m2 += i;
580 s2 += i;
581 }
582 if (b2 > 0)
575 i = ((s5 ? hi0bits(S->x[S->wds-1]) : ULbits - 1) - s2 - 4) & kmask;
576 m2 += i;
577 if ((b2 += i) > 0)
583 b = lshift(b, b2);
578 b = lshift(b, b2);
584 if (s2 > 0)
579 if ((s2 += i) > 0)
585 S = lshift(S, s2);
586 if (k_check) {
587 if (cmp(b,S) < 0) {
588 k--;
589 b = multadd(b, 10, 0); /* we botched the k estimate */
590 if (leftright)
591 mhi = multadd(mhi, 10, 0);
592 ilim = ilim1;

--- 48 unchanged lines hidden (view full) ---

641 else {
642 dig++;
643 inex = STRTOG_Inexhi;
644 }
645 *s++ = dig;
646 goto ret;
647 }
648#endif
580 S = lshift(S, s2);
581 if (k_check) {
582 if (cmp(b,S) < 0) {
583 k--;
584 b = multadd(b, 10, 0); /* we botched the k estimate */
585 if (leftright)
586 mhi = multadd(mhi, 10, 0);
587 ilim = ilim1;

--- 48 unchanged lines hidden (view full) ---

636 else {
637 dig++;
638 inex = STRTOG_Inexhi;
639 }
640 *s++ = dig;
641 goto ret;
642 }
643#endif
649 if (j < 0 || j == 0 && !mode
644 if (j < 0 || (j == 0 && !mode
650#ifndef ROUND_BIASED
651 && !(bits[0] & 1)
652#endif
645#ifndef ROUND_BIASED
646 && !(bits[0] & 1)
647#endif
653 ) {
648 )) {
654 if (rdir && (b->wds > 1 || b->x[0])) {
655 if (rdir == 2) {
656 inex = STRTOG_Inexlo;
657 goto accept;
658 }
659 while (cmp(S,mhi) > 0) {
660 *s++ = dig;
661 mhi1 = multadd(mhi, 10, 0);

--- 6 unchanged lines hidden (view full) ---

668 if (dig++ == '9')
669 goto round_9_up;
670 inex = STRTOG_Inexhi;
671 goto accept;
672 }
673 if (j1 > 0) {
674 b = lshift(b, 1);
675 j1 = cmp(b, S);
649 if (rdir && (b->wds > 1 || b->x[0])) {
650 if (rdir == 2) {
651 inex = STRTOG_Inexlo;
652 goto accept;
653 }
654 while (cmp(S,mhi) > 0) {
655 *s++ = dig;
656 mhi1 = multadd(mhi, 10, 0);

--- 6 unchanged lines hidden (view full) ---

663 if (dig++ == '9')
664 goto round_9_up;
665 inex = STRTOG_Inexhi;
666 goto accept;
667 }
668 if (j1 > 0) {
669 b = lshift(b, 1);
670 j1 = cmp(b, S);
676 if ((j1 > 0 || j1 == 0 && dig & 1)
671#ifdef ROUND_BIASED
672 if (j1 >= 0 /*)*/
673#else
674 if ((j1 > 0 || (j1 == 0 && dig & 1))
675#endif
677 && dig++ == '9')
678 goto round_9_up;
679 inex = STRTOG_Inexhi;
680 }
681 if (b->wds > 1 || b->x[0])
682 inex = STRTOG_Inexlo;
683 accept:
684 *s++ = dig;

--- 28 unchanged lines hidden (view full) ---

713 if (i >= ilim)
714 break;
715 b = multadd(b, 10, 0);
716 }
717
718 /* Round off last digit */
719
720 if (rdir) {
676 && dig++ == '9')
677 goto round_9_up;
678 inex = STRTOG_Inexhi;
679 }
680 if (b->wds > 1 || b->x[0])
681 inex = STRTOG_Inexlo;
682 accept:
683 *s++ = dig;

--- 28 unchanged lines hidden (view full) ---

712 if (i >= ilim)
713 break;
714 b = multadd(b, 10, 0);
715 }
716
717 /* Round off last digit */
718
719 if (rdir) {
721 if (rdir == 2 || b->wds <= 1 && !b->x[0])
720 if (rdir == 2 || (b->wds <= 1 && !b->x[0]))
722 goto chopzeros;
723 goto roundoff;
724 }
725 b = lshift(b, 1);
726 j = cmp(b, S);
721 goto chopzeros;
722 goto roundoff;
723 }
724 b = lshift(b, 1);
725 j = cmp(b, S);
727 if (j > 0 || j == 0 && dig & 1) {
726#ifdef ROUND_BIASED
727 if (j >= 0)
728#else
729 if (j > 0 || (j == 0 && dig & 1))
730#endif
731 {
728 roundoff:
729 inex = STRTOG_Inexhi;
730 while(*--s == '9')
731 if (s == s0) {
732 k++;
733 *s++ = '1';
734 goto ret;
735 }

--- 25 unchanged lines hidden ---
732 roundoff:
733 inex = STRTOG_Inexhi;
734 while(*--s == '9')
735 if (s == s0) {
736 k++;
737 *s++ = '1';
738 goto ret;
739 }

--- 25 unchanged lines hidden ---