On Fri, 21 Mar 2025, Jakub Jelinek wrote: > On Fri, Mar 21, 2025 at 08:32:51AM +0100, Richard Biener wrote: > > > 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. > > Actually, thinking about it some more, perhaps it would be enough to just > call real_from_decimal with a different precision the second time + adjust > the string.
So the issue is in binary_initial_from_float128 where formerly strfromf128(ach, sizeof(ach), "%.0f", value); ensured that after value *= get_power_of_ten(rdigits); the result was rounded to an integer (string). As I removed the string detour I forgot to apply such rounding. The following incremental patch fixes your testcase for me. I'm going to merge this with the pending patch, I'll also add the test as one in cobol.dg as well as the other testcase I created myself when fixing the output formatting side. Richard. diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 7f1b78dbf9a..989ccceb42e 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -15254,11 +15254,13 @@ binary_initial_from_float128(cbl_field_t *field, int rdigits, // data.initial member of the incoming field char *retval = NULL; - // We need to adjust value so that it has no decimal places + // We need to adjust value so that it has no decimal places if( rdigits ) { REAL_VALUE_TYPE pow10 = real_powi10 (rdigits); real_arithmetic (&value, MULT_EXPR, &value, &pow10); + // But make sure to round properly + real_round (&value, VOIDmode, &value); } // We need to make sure that the resulting string will fit into // a number with 'digits' digits