]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Add tolerance to real value comparisons.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 17 Oct 2024 20:39:09 +0000 (13:39 -0700)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 17 Oct 2024 20:49:04 +0000 (13:49 -0700)
gcc/testsuite/ChangeLog:

PR fortran/105361
* gfortran.dg/pr105361.f90: In the comparisons of
real values after a read, use a tolerance so that
subtle differences in results between different
architectures do not fail.

gcc/testsuite/gfortran.dg/pr105361.f90

index 62821c2802dfd08315fce1293b6de7452b1a2334..fc09ad6c2e150f2ac593e1c465882350c7d7e545 100644 (file)
@@ -3,7 +3,7 @@
 module x
   implicit none
   type foo
-     real :: r
+     real(4) :: r
   end type foo
   interface read(formatted)
      module procedure read_formatted
@@ -25,17 +25,21 @@ program main
   use x
   implicit none
   type(foo) :: a, b
-  real :: c, d
+  real(4) :: c, d
+  c = 0.0_4
+  d = 0.0_4
   open(10, access="stream") 
   write(10) "1 2" // NEW_LINE('A')
   close(10)
   open(10)
   read(10,*) c, d
-  if ((c /= 1.0) .or. (d /= 2.0)) stop 1
+  if ((abs(c - 1.0_4) .gt. 0.001_4) .or. (abs(d - 2.0_4) .gt. 0.001_4)) stop 1
   rewind(10)
   !print *, c,d
+  a%r = 0.0_4
+  b%r = 0.0_4
   read (10,*) a, b
   close(10, status="delete")
-  if ((a%r /= 1.0) .or. (b%r /= 2.0)) stop 2
+  if ((abs(a%r - 1.0_4) .gt. 0.001_4) .or. (abs(b%r - 2.0_4) .gt. 0.001_4)) stop 2
   !print *, a,b
 end program main