This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, final] Formatted output of IEEE exceptional values
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>, patch <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 22 Jul 2005 23:27:26 -0700
- Subject: [PATCH, final] Formatted output of IEEE exceptional values
The attached patch and test case reflect the additional case of a field
width specified as zero.
F2003 says: "When w is zero, the processor selects the field width".
I have selected that width to be 4 in the case of exceptional values to
output -Inf or +Inf
F2003 also says: "If w is less than 3, the field is filled with
asterisks; otherwise; if w is less than 8, 'Inf' is produced".
The negative sign is not optional, so I have interpreted the case of w=3
to be -Inf which exceeds the field width and so asterisks are produced.
The result is as follows:
F0.0 | -Inf| +Inf| NaN| NaN|
F1.0 | *| *| *| *|
F2.0 | **| **| **| **|
F3.0 | ***| Inf| NaN| NaN|
F4.0 | -Inf| +Inf| NaN| NaN|
F5.0 | -Inf| +Inf| NaN| NaN|
F6.0 | -Inf| +Inf| NaN| NaN|
F7.0 | -Inf| +Inf| NaN| NaN|
F8.0 | -Inf| +Inf| NaN| NaN|
F9.0 | -Infinity| +Infinity| NaN| NaN|
F10.0 | -Infinity| +Infinity| NaN| NaN|
Note that in the case of F0 the four characters will be written to the
right of the current position since there is no actual field to align with.
Bubblestrapped and reg tested.
2005-07-23 Jerry DeLisle <jvdelisle@verizon.net>
* io/write.c (write_float): Revise output of IEEE exceptional
values to comply with F95 and F2003 standards.
OK for mainline and 4.0?
Regards,
Jerry
Index: write.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/write.c,v
retrieving revision 1.43
diff -c -3 -p -r1.43 write.c
*** write.c 17 Jul 2005 20:28:14 -0000 1.43
--- write.c 23 Jul 2005 05:16:58 -0000
*************** write_float (fnode *f, const char *sourc
*** 772,777 ****
--- 772,778 ----
if (res == 0)
{
nb = f->u.real.w;
+ if (nb == 0) nb = 4;
p = write_block (nb);
if (nb < 3)
{
*************** write_float (fnode *f, const char *sourc
*** 784,792 ****
if (res != 0)
{
if (signbit(n))
! fin = '-';
else
! fin = '+';
if (nb > 8)
memcpy(p + nb - 8, "Infinity", 8);
--- 785,800 ----
if (res != 0)
{
if (signbit(n))
! {
! if (nb == 3)
! {
! memset (p, '*',nb);
! return;
! }
! fin = '-';
! }
else
! fin = '+';
if (nb > 8)
memcpy(p + nb - 8, "Infinity", 8);
Index: nan_inf_fmt.f90
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gfortran.fortran-torture/execute/nan_inf_fmt.f90,v
retrieving revision 1.2
diff -c -3 -p -r1.2 nan_inf_fmt.f90
*** nan_inf_fmt.f90 18 Jul 2005 00:07:53 -0000 1.2
--- nan_inf_fmt.f90 23 Jul 2005 06:11:53 -0000
***************
*** 12,17 ****
--- 12,25 ----
neg_inf = -1.0/zero
nan = zero/zero
+ ! check a field width = 0
+ fmt = '(F0.0)'
+ write(l,fmt=fmt)pos_inf
+ if (l.ne.'+Inf') call abort
+ write(l,fmt=fmt)neg_inf
+ if (l.ne.'-Inf') call abort
+ write(l,fmt=fmt)nan
+ if (l.ne.' NaN') call abort
! check a field width < 3
fmt = '(F2.0)'
***************
*** 27,33 ****
write(l,fmt=fmt)pos_inf
if (l.ne.'Inf') call abort
write(l,fmt=fmt)neg_inf
! if (l.ne.'Inf') call abort
write(l,fmt=fmt)nan
if (l.ne.'NaN') call abort
--- 35,41 ----
write(l,fmt=fmt)pos_inf
if (l.ne.'Inf') call abort
write(l,fmt=fmt)neg_inf
! if (l.ne.'***') call abort
write(l,fmt=fmt)nan
if (l.ne.'NaN') call abort