re PR libfortran/47434 (Wrong field width for NaN with (F0.n) formatting)

2011-01-29  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	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
This commit is contained in:
Jerry DeLisle 2011-01-29 17:31:04 +00:00
parent 69ca976728
commit 6e0576ee50
2 changed files with 44 additions and 14 deletions

View File

@ -1,3 +1,9 @@
2011-01-29 Jerry DeLisle <jvdelisle@gcc.gnu.org>
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 <kai.tietz@onevision.com> 2011-01-29 Kai Tietz <kai.tietz@onevision.com>
* intrinsics/ctime.c (ctime_r): Improve implementation. * intrinsics/ctime.c (ctime_r): Improve implementation.
@ -35,6 +41,12 @@
* config.h.in: Regenerate. * config.h.in: Regenerate.
* configure: Regenerate. * configure: Regenerate.
2011-01-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/47285
* io/write_float.def (write_infnan): Adjust processor selected width
to 3 if NaN.
2011-01-26 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2011-01-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/47285 PR libgfortran/47285

View File

@ -660,15 +660,26 @@ write_infnan (st_parameter_dt *dtp, const fnode *f, int isnan_flag, int sign_bit
{ {
char * p, fin; char * p, fin;
int nb = 0; int nb = 0;
sign_t sign;
int mark;
if (f->format != FMT_B && f->format != FMT_O && f->format != FMT_Z) 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; nb = f->u.real.w;
/* If the field width is zero, the processor must select a width /* If the field width is zero, the processor must select a width
not zero. 4 is chosen to allow output of '-Inf' or '+Inf' */ 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); p = write_block (dtp, nb);
if (p == NULL) if (p == NULL)
return; 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))) if (unlikely (is_char4_unit (dtp)))
{ {
gfc_char4_t *p4 = (gfc_char4_t *) p; gfc_char4_t *p4 = (gfc_char4_t *) p;
if (nb > 8)
if (nb > mark)
/* We have room, so output 'Infinity' */ /* We have room, so output 'Infinity' */
memcpy4 (p4 + nb - 8, "Infinity", 8); memcpy4 (p4 + nb - 8, "Infinity", 8);
else 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' */ for the sign and 'Infinity' so we go with 'Inf' */
memcpy4 (p4 + nb - 3, "Inf", 3); memcpy4 (p4 + nb - 3, "Inf", 3);
if (nb < 9 && nb > 3) if (sign == S_PLUS || sign == S_MINUS)
/* Put the sign in front of Inf */ {
p4[nb - 4] = (gfc_char4_t) fin; if (nb < 9 && nb > 3)
else if (nb > 8) /* Put the sign in front of Inf */
/* Put the sign in front of Infinity */ p4[nb - 4] = (gfc_char4_t) fin;
p4[nb - 9] = (gfc_char4_t) fin; else if (nb > 8)
/* Put the sign in front of Infinity */
p4[nb - 9] = (gfc_char4_t) fin;
}
return; return;
} }
if (nb > 8) if (nb > mark)
/* We have room, so output 'Infinity' */ /* We have room, so output 'Infinity' */
memcpy(p + nb - 8, "Infinity", 8); memcpy(p + nb - 8, "Infinity", 8);
else 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' */ for the sign and 'Infinity' so we go with 'Inf' */
memcpy(p + nb - 3, "Inf", 3); memcpy(p + nb - 3, "Inf", 3);
if (nb < 9 && nb > 3) if (sign == S_PLUS || sign == S_MINUS)
p[nb - 4] = fin; /* Put the sign in front of Inf */ {
else if (nb > 8) if (nb < 9 && nb > 3)
p[nb - 9] = fin; /* Put the sign in front of Infinity */ 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 else
{ {