]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libfortran/33469 (Default formats for real input are not precise enough)
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Tue, 2 Oct 2007 23:27:51 +0000 (23:27 +0000)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Tue, 2 Oct 2007 23:27:51 +0000 (23:27 +0000)
PR libfortran/33469

* io/write.c (write_real): Widen the default formats.

* gfortran.dg/default_format_1.f90: New test.
* gfortran.dg/default_format_2.f90: New test.
* gfortran.dg/namelist_print_1.f: Adjust expected output.
* gfortran.dg/real_const_3.f90: Adjust expected output.

From-SVN: r128967

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/default_format_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/default_format_2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/namelist_print_1.f
gcc/testsuite/gfortran.dg/real_const_3.f90
libgfortran/ChangeLog
libgfortran/io/write.c

index 2e45a08cff4b53d2b7ba974e5a36954edaa2b8e9..adab396193e743659630c1c35364ac09ccb8d13a 100644 (file)
@@ -1,3 +1,11 @@
+2007-10-03  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR libfortran/33469
+       * gfortran.dg/default_format_1.f90: New test.
+       * gfortran.dg/default_format_2.f90: New test.
+       * gfortran.dg/namelist_print_1.f: Adjust expected output.
+       * gfortran.dg/real_const_3.f90: Adjust expected output.
+
 2007-10-02  Richard Sandiford  <rsandifo@nildram.co.uk>
 
        * gcc.target/mips/mips.exp (setup_mips_tests): Set mips_abi to the
diff --git a/gcc/testsuite/gfortran.dg/default_format_1.f90 b/gcc/testsuite/gfortran.dg/default_format_1.f90
new file mode 100644 (file)
index 0000000..6183a34
--- /dev/null
@@ -0,0 +1,101 @@
+! { dg-do run }
+!
+! This tests that the default formats for formatted I/O of reals are
+! wide enough and have enough precision, by checking that values can
+! be written and read back.
+!
+module test_default_format
+  interface test
+    module procedure test_r4
+    module procedure test_r8
+  end interface test
+
+  integer, parameter :: count = 200
+
+contains
+  function test_r4 (start, towards) result (res)
+    integer, parameter :: k = 4
+    integer, intent(in) :: towards
+    real(k), intent(in) :: start
+
+    integer :: res, i
+    real(k) :: x, y
+    character(len=100) :: s
+
+    res = 0
+
+    if (towards >= 0) then
+      x = start
+      do i = 0, count
+        write (s,*) x
+        read (s,*) y
+        if (y /= x) res = res + 1
+        x = nearest(x,huge(x))
+      end do
+    end if
+
+    if (towards <= 0) then
+      x = start
+      do i = 0, count
+        write (s,*) x
+        read (s,*) y
+        if (y /= x) res = res + 1
+        x = nearest(x,-huge(x))
+      end do
+    end if
+  end function test_r4
+
+  function test_r8 (start, towards) result (res)
+    integer, parameter :: k = 8
+    integer, intent(in) :: towards
+    real(k), intent(in) :: start
+
+    integer :: res, i
+    real(k) :: x, y
+    character(len=100) :: s
+
+    res = 0
+
+    if (towards >= 0) then
+      x = start
+      do i = 0, count
+        write (s,*) x
+        read (s,*) y
+        if (y /= x) res = res + 1
+        x = nearest(x,huge(x))
+      end do
+    end if
+
+    if (towards <= 0) then
+      x = start
+      do i = 0, count
+        write (s,*) x
+        read (s,*) y
+        if (y /= x) res = res + 1
+        x = nearest(x,-huge(x))
+      end do
+    end if
+  end function test_r8
+
+end module test_default_format
+
+program main
+  use test_default_format
+
+  if (test (1.0_4, 0) /= 0) call abort
+  if (test (0.0_4, 0) /= 0) call abort
+  if (test (tiny(0.0_4), 0) /= 0) call abort
+  if (test (-tiny(0.0_4), 0) /= 0) call abort
+  if (test (huge(0.0_4), -1) /= 0) call abort
+  if (test (-huge(0.0_4), 1) /= 0) call abort
+
+  if (test (1.0_8, 0) /= 0) call abort
+  if (test (0.0_8, 0) /= 0) call abort
+  if (test (tiny(0.0_8), 0) /= 0) call abort
+  if (test (-tiny(0.0_8), 0) /= 0) call abort
+  if (test (huge(0.0_8), -1) /= 0) call abort
+  if (test (-huge(0.0_8), 1) /= 0) call abort
+
+end program main
+!
+! { dg-final { cleanup-modules "test_default_format" } }
diff --git a/gcc/testsuite/gfortran.dg/default_format_2.f90 b/gcc/testsuite/gfortran.dg/default_format_2.f90
new file mode 100644 (file)
index 0000000..af6d4a6
--- /dev/null
@@ -0,0 +1,64 @@
+! { dg-do run }
+! { dg-require-effective-target fortran_large_real }
+!
+! This tests that the default formats for formatted I/O of reals are
+! wide enough and have enough precision, by checking that values can
+! be written and read back.
+!
+module test_default_format
+  interface test
+    module procedure test_rl
+  end interface test
+
+  integer, parameter :: kl = selected_real_kind (precision (0.0_8) + 1)
+  integer, parameter :: count = 200
+
+contains
+
+  function test_rl (start, towards) result (res)
+    integer, parameter :: k = kl
+    integer, intent(in) :: towards
+    real(k), intent(in) :: start
+
+    integer :: res, i
+    real(k) :: x, y
+    character(len=100) :: s
+
+    res = 0
+
+    if (towards >= 0) then
+      x = start
+      do i = 0, count
+        write (s,*) x
+        read (s,*) y
+        if (y /= x) res = res + 1
+        x = nearest(x,huge(x))
+      end do
+    end if
+
+    if (towards <= 0) then
+      x = start
+      do i = 0, count
+        write (s,*) x
+        read (s,*) y
+        if (y /= x) res = res + 1
+        x = nearest(x,-huge(x))
+      end do
+    end if
+  end function test_rl
+
+end module test_default_format
+
+program main
+  use test_default_format
+
+  if (test (1.0_kl, 0) /= 0) call abort
+  if (test (0.0_kl, 0) /= 0) call abort
+  if (test (tiny(0.0_kl), 0) /= 0) call abort
+  if (test (-tiny(0.0_kl), 0) /= 0) call abort
+  if (test (huge(0.0_kl), -1) /= 0) call abort
+  if (test (-huge(0.0_kl), 1) /= 0) call abort
+
+end program main
+!
+! { dg-final { cleanup-modules "test_default_format" } }
index dfd2841f0229a546db842408c4564463e9059171..5c0e7759088dc5132b4234d3b4abdbcb536a6894 100644 (file)
@@ -9,5 +9,5 @@
       namelist /mynml/ x
       x = 1
 ! ( dg-output "^" }
-      print mynml ! { dg-output "&MYNML(\n|\r\n|\r) X=  1.000000    ,  /(\n|\r\n|\r)" }
+      print mynml ! { dg-output "&MYNML(\n|\r\n|\r) X= 1.00000000    ,  /(\n|\r\n|\r)" }
       end
index 533b4af65f025a8f35a94a3f0372a342719add02..d6b2a968d8eeb52c404299c61b1f3dfd5ea57d83 100644 (file)
@@ -27,15 +27,15 @@ program main
 
 end program main
 !{ dg-output "      \\+Infinity(\n|\r\n|\r)" }
-!{ dg-output "   0.000000    (\n|\r\n|\r)" }
-!{ dg-output "      -Infinity(\n|\r\n|\r)" }
-!{ dg-output "            NaN(\n|\r\n|\r)" }
-!{ dg-output "            NaN(\n|\r\n|\r)" }
-!{ dg-output "      -Infinity(\n|\r\n|\r)" }
-!{ dg-output "      -Infinity(\n|\r\n|\r)" }
-!{ dg-output "      \\+Infinity(\n|\r\n|\r)" }
-!{ dg-output "            NaN(\n|\r\n|\r)" }
-!{ dg-output " \\(           NaN,           NaN\\)(\n|\r\n|\r)" }
-!{ dg-output " \\(           NaN,           NaN\\)(\n|\r\n|\r)" }
-!{ dg-output " \\(     \\+Infinity,     -Infinity\\)(\n|\r\n|\r)" }
-!{ dg-output " \\(  0.000000    , -0.000000    \\)(\n|\r\n|\r)" }
+!{ dg-output "   0.0000000    (\n|\r\n|\r)" }
+!{ dg-output "       -Infinity(\n|\r\n|\r)" }
+!{ dg-output "             NaN(\n|\r\n|\r)" }
+!{ dg-output "             NaN(\n|\r\n|\r)" }
+!{ dg-output "       -Infinity(\n|\r\n|\r)" }
+!{ dg-output "       -Infinity(\n|\r\n|\r)" }
+!{ dg-output "       \\+Infinity(\n|\r\n|\r)" }
+!{ dg-output "             NaN(\n|\r\n|\r)" }
+!{ dg-output " \\(            NaN,            NaN\\)(\n|\r\n|\r)" }
+!{ dg-output " \\(            NaN,            NaN\\)(\n|\r\n|\r)" }
+!{ dg-output " \\(      \\+Infinity,      -Infinity\\)(\n|\r\n|\r)" }
+!{ dg-output " \\(  0.0000000    , -0.0000000    \\)(\n|\r\n|\r)" }
index aaa37a4a5030f443a5628df2af732f31a445e33a..7392997e2af839adbba3c353deab7b88f39fd9df 100644 (file)
@@ -1,3 +1,8 @@
+2007-10-02  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR fortran/33469
+       * io/write.c (write_real): Widen the default formats.
+
 2007-09-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/33400
index 4792a222b9a7e07fde184f0f043784f66a9815c2..84b695fa883bd09e3e20e97572585fe9846dd0e3 100644 (file)
@@ -698,18 +698,18 @@ write_real (st_parameter_dt *dtp, const char *source, int length)
   switch (length)
     {
     case 4:
-      f.u.real.w = 14;
-      f.u.real.d = 7;
+      f.u.real.w = 15;
+      f.u.real.d = 8;
       f.u.real.e = 2;
       break;
     case 8:
-      f.u.real.w = 23;
-      f.u.real.d = 15;
+      f.u.real.w = 25;
+      f.u.real.d = 17;
       f.u.real.e = 3;
       break;
     case 10:
-      f.u.real.w = 28;
-      f.u.real.d = 19;
+      f.u.real.w = 29;
+      f.u.real.d = 20;
       f.u.real.e = 4;
       break;
     case 16: