From 35fd722b61b9a1603c204b0d493b2a56fd058cde Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Sun, 24 Jul 2005 02:24:15 +0000 Subject: [PATCH] write.c (write_float): Revise output of IEEE exceptional values to comply with F95 and F2003 standards. 2005-07-23 Jerry DeLisle * io/write.c (write_float): Revise output of IEEE exceptional values to comply with F95 and F2003 standards. From-SVN: r102324 --- libgfortran/ChangeLog | 5 +++++ libgfortran/io/write.c | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 747ef9e9023..3e37aacb211 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +2005-07-23 Jerry DeLisle + + * io/write.c (write_float): Revise output of IEEE exceptional + values to comply with F95 and F2003 standards. + 2005-07-22 Jerry DeLisle PR libfortran/22570 diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 54bf480fdf3..a702de18a2a 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -772,6 +772,11 @@ write_float (fnode *f, const char *source, int len) if (res == 0) { 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; p = write_block (nb); if (nb < 3) { @@ -784,18 +789,43 @@ write_float (fnode *f, const char *source, int len) if (res != 0) { if (signbit(n)) - fin = '-'; + { + + /* If the sign is negative and the width is 3, there is + insufficient room to output '-Inf', so output asterisks */ + + if (nb == 3) + { + memset (p, '*',nb); + return; + } + + /* The negative sign is mandatory */ + + fin = '-'; + } else - fin = '+'; + + /* The positive sign is optional, but we output it for + consistency */ + + fin = '+'; if (nb > 8) + + /* We have room, so output 'Infinity' */ + memcpy(p + nb - 8, "Infinity", 8); else + + /* For the case of width equals 8, there is not enough room + 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; + p[nb - 4] = fin; /* Put the sign in front of Inf */ else if (nb > 8) - p[nb - 9] = fin; + p[nb - 9] = fin; /* Put the sign in front of Infinity */ } else memcpy(p + nb - 3, "NaN", 3);