On Thu, 20 Mar 2025, Jakub Jelinek wrote:

> On Thu, Mar 20, 2025 at 03:30:30PM -0500, Robert Dubner wrote:
> > Let me find one inky-dink example.  Talk amongst yourselves...here we go.
> > 
> >         identification          division.
> >         program-id.             prog.
> >         data                    division.
> >         working-storage         section.
> >         77 var8 PIC 999V9(8) COMP-5 .
> >         77 var555 PIC 999V99999999 COMP-5 VALUE 555.55555555.
> >         procedure               division.
> >         move 555.55555555 to var8
> >         add 0.00000001 TO var555 giving var8 rounded
> >         if var8 not equal to 555.55555556 display var8 " should be
> > 555.55555556".
> >         end program             prog.
> > 
> > With your patches, the output is
> >     
> >     555.55555555 should be 555.55555556
> 
> Thanks.
> Now, the code certainly could try to do the rounding of the last digits
> based on the remaining digits in the string that are being discarded,
> if followed by 0-4, don't change anything, if followed by 6-9, increase
> last digit, if followed by 5 and any non-zero digit, increase too, if followed
> by 5 and all zeros, round to even.
> But I'm afraid it can have double rounding, when round_to_decimal rounds
> for the precision 33 printing something e.g. with 49999999999999999999 at
> the end to 500000000000 and this second rounding again.

I think this must go wrong at a different place than the previous output
thing given it's the

  if var8 not equal to 555.55555556

test that misbehaves.  So it might be a similar issue at the input
side (I was not very careful when converting the string stuff, esp.
with regard to the precision specifiers in the format strings).

> So I really think we should go to mpfr, I can implement it tomorrow unless
> Richi wants to do that.

Go to mpfr for the string conversions?  Yeah, maybe that's a good
idea.

Richard.

Reply via email to