From: Jerry DeLisle Date: Sat, 29 Jan 2011 17:31:04 +0000 (+0000) Subject: re PR libfortran/47434 (Wrong field width for NaN with (F0.n) formatting) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e0576ee50941e967101fc54171e9172d471b73f;p=gcc.git re PR libfortran/47434 (Wrong field width for NaN with (F0.n) formatting) 2011-01-29 Jerry DeLisle PR libgfortran/47434 * io/write_float.def (write_infnan): Use calculate_sign to determine if the sign should be given and check field widths accordingly. From-SVN: r169390 --- diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 5e0c7623e97..dc10be50cb0 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2011-01-29 Jerry DeLisle + + PR libgfortran/47434 + * io/write_float.def (write_infnan): Use calculate_sign to determine + if the sign should be given and check field widths accordingly. + 2011-01-29 Kai Tietz * intrinsics/ctime.c (ctime_r): Improve implementation. @@ -35,6 +41,12 @@ * config.h.in: Regenerate. * configure: Regenerate. +2011-01-26 Jerry DeLisle + + PR libgfortran/47285 + * io/write_float.def (write_infnan): Adjust processor selected width + to 3 if NaN. + 2011-01-26 Jerry DeLisle PR libgfortran/47285 diff --git a/libgfortran/io/write_float.def b/libgfortran/io/write_float.def index a74b34a0214..a77b3042768 100644 --- a/libgfortran/io/write_float.def +++ b/libgfortran/io/write_float.def @@ -660,15 +660,26 @@ write_infnan (st_parameter_dt *dtp, const fnode *f, int isnan_flag, int sign_bit { char * p, fin; int nb = 0; + sign_t sign; + int mark; if (f->format != FMT_B && f->format != FMT_O && f->format != FMT_Z) { + sign = calculate_sign (dtp, sign_bit); + mark = (sign == S_PLUS || sign == S_MINUS) ? 8 : 7; + nb = f->u.real.w; /* If the field width is zero, the processor must select a width not zero. 4 is chosen to allow output of '-Inf' or '+Inf' */ - if (nb == 0) nb = 4; + if (nb == 0) + { + if (isnan_flag) + nb = 3; + else + nb = (sign == S_PLUS || sign == S_MINUS) ? 4 : 3; + } p = write_block (dtp, nb); if (p == NULL) return; @@ -720,24 +731,28 @@ write_infnan (st_parameter_dt *dtp, const fnode *f, int isnan_flag, int sign_bit if (unlikely (is_char4_unit (dtp))) { gfc_char4_t *p4 = (gfc_char4_t *) p; - if (nb > 8) + + if (nb > mark) /* We have room, so output 'Infinity' */ memcpy4 (p4 + nb - 8, "Infinity", 8); else - /* For the case of width equals 8, there is not enough room + /* For the case of width equals mark, there is not enough room for the sign and 'Infinity' so we go with 'Inf' */ memcpy4 (p4 + nb - 3, "Inf", 3); - if (nb < 9 && nb > 3) - /* Put the sign in front of Inf */ - p4[nb - 4] = (gfc_char4_t) fin; - else if (nb > 8) - /* Put the sign in front of Infinity */ - p4[nb - 9] = (gfc_char4_t) fin; + if (sign == S_PLUS || sign == S_MINUS) + { + if (nb < 9 && nb > 3) + /* Put the sign in front of Inf */ + p4[nb - 4] = (gfc_char4_t) fin; + else if (nb > 8) + /* Put the sign in front of Infinity */ + p4[nb - 9] = (gfc_char4_t) fin; + } return; } - if (nb > 8) + if (nb > mark) /* We have room, so output 'Infinity' */ memcpy(p + nb - 8, "Infinity", 8); else @@ -745,10 +760,13 @@ write_infnan (st_parameter_dt *dtp, const fnode *f, int isnan_flag, int sign_bit for the sign and 'Infinity' so we go with 'Inf' */ memcpy(p + nb - 3, "Inf", 3); - if (nb < 9 && nb > 3) - p[nb - 4] = fin; /* Put the sign in front of Inf */ - else if (nb > 8) - p[nb - 9] = fin; /* Put the sign in front of Infinity */ + if (sign == S_PLUS || sign == S_MINUS) + { + if (nb < 9 && nb > 3) + p[nb - 4] = fin; /* Put the sign in front of Inf */ + else if (nb > 8) + p[nb - 9] = fin; /* Put the sign in front of Infinity */ + } } else {