OK,
A new program that demonstrates 32-bit has different round-off.
program main
use iso_fortran_env
implicit none
double precision :: a,b,c,d, one = 1
logical :: f1, f2
write (*,*) 'Version : ',compiler_version ()
write (*,*) 'Options : ',compiler_options ()
a = 1.0d0/3.0d0
b = 2.0d0/3.0d0
write(*,11) 'a = ',a
write(*,11) 'b = ',b
c = a + b
write(*,11) 'a + b = ',a+b
write(*,11) 'c = ',c
f1 = (c > one)
f2 = (c < one)
write(*,*) 'c is smaller than 1.0 = ',f2
write(*,*) 'c is larger than 1.0 = ',f1
f1 = (a+b > one)
f2 = (a+b < one)
write(*,*) 'a+b is smaller than 1.0 = ',f2
write(*,*) 'a+b is larger than 1.0 = ',f1
c = abs(mod(c,one))
d = abs(mod(a+b,one))
write(*,11) 'abs(mod(c,1.0)) = ',c
write(*,11) 'abs(mod(a+b,1.0)) = ',d
write(*,11) 'one-(a+b) = ',one-(a+b)
write(*,11) '(one-a)-b = ',(one-a)-b
write(*,11) 'one-a-b = ',one-a-b
11 format (a,e24.18)
end
Results for revised program:
Version : FTN95 v9.04.0
Options : CHECKMATE;ECHO_OPTIONS;ERROR_NUMBERS;IMPLICIT_NONE;INTL;LINK;LOGL;NO_BANNER;UNLIMITED_ERRORS;VS7;
a = 0.333333333333333315E+00
b = 0.666666666666666630E+00
a + b = 0.100000000000000000E+01
c = 0.100000000000000000E+01
c is smaller than 1.0 = F
c is larger than 1.0 = F
a+b is smaller than 1.0 = T
a+b is larger than 1.0 = F
abs(mod(c,1.0)) = 0.000000000000000000E+00
abs(mod(a+b,1.0)) = 0.100000000000000000E+01
one-(a+b) = 0.555111512312578271E-16
(one-a)-b = 0.555111512312578271E-16
one-a-b = 0.555111512312578271E-16
Version : FTN95 v9.04.0
Options : 64;CHECKMATE;ECHO_OPTIONS;ERROR_NUMBERS;IMPLICIT_NONE;INTL;LINK;LOGL;NO_BANNER;UNLIMITED_ERRORS;VS7;
a = 0.333333333333333303E+00
b = 0.666666666666666606E+00
a + b = 0.100000000000000000E+01
c = 0.100000000000000000E+01
c is smaller than 1.0 = F
c is larger than 1.0 = F
a+b is smaller than 1.0 = F
a+b is larger than 1.0 = F
abs(mod(c,1.0)) = 0.000000000000000000E+00
abs(mod(a+b,1.0)) = 0.000000000000000000E+00
one-(a+b) = 0.000000000000000000E+00
(one-a)-b = 0.111022302462515654E-15
one-a-b = 0.111022302462515654E-15
Version : GCC version 14.1.0
Options : -cpp -iprefix C:/Program Files (x86)/gcc_eq/gcc_14.1.0/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/ -U_REENTRANT -mtune=generic -march=x86-64 -fno-underscoring -fdollar-ok
a = 0.333333333333333315E+00
b = 0.666666666666666630E+00
a + b = 0.100000000000000000E+01
c = 0.100000000000000000E+01
c is smaller than 1.0 = F
c is larger than 1.0 = F
a+b is smaller than 1.0 = F
a+b is larger than 1.0 = F
abs(mod(c,1.0)) = 0.000000000000000000E+00
abs(mod(a+b,1.0)) = 0.000000000000000000E+00
one-(a+b) = 0.000000000000000000E+00
(one-a)-b = 0.111022302462515654E-15
one-a-b = 0.111022302462515654E-15
The differing results demonstrate that these type of tests should account for round-off uncertainty.
I am really not sure if 32-bit uses 80-bit registers for f2 = (a+b < one) ?
c (= a+b) would be rounded to a 64-bit real.