Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Interesting Problem

JohnNichols
Valued Contributor III
344 Views

 

 

program jellby0
implicit none
double precision znq,zmax,zmin,t3,vz, dum1, dum2,dum3,dum4,dum5
znq  =  1.0D0
zmax =  znq+1.0D0
zmin = -1.00000000000000D99
t3   =  1.00000000000000D0
dum1 = zmax-zmin
dum2 = dum1*t3
dum3 = znq - dum2
dum4 = dum3 - zmin
vz   =  zNQ-(zmax-zmin)*t3-zmin
dum5 = abs(zmin)*0.05D0
write(*,10)"vz               = ",vz, "znq - zmax       = ",(zNQ-zmax),"zmax - zmin      = ",dum1,"dum1*t3          = ",dum2,"znq - dum2       = ",dum3,"theoretically vz = ",dum4
10 Format (6(A,es20.12,/))
write(*,20)"error            = ",dum5
20 Format(6(A,es20.12,/))
! both should be -1 (if calculated with infinite precision arithmetic)
end program

 

 

We do not live in a world of infinite precision, even the universe must have a countable number of atoms for as far as we can see.  

So the real answer depends on the error in your numbers, introduced by whatever method, so both 1 and 0 both answers, which is more correct is a matter of opinion, in terms of kindergarten math, -1 in terms of real physics, it is a cat in two boxes. 

This is the same as the integer problem.  

Screenshot 2024-01-10 143828.png

Line 8 should signal a flag in the addition operation that the first number is smaller than the error on the second number, just from the programming mathematics.  

I meant to add this past the post by @mecej4 in the jelby posts, but I made a mistake, apologies.  

This is like the thought experiments given in exams in Pure Math 1 at ANU.  

 

0 Kudos
1 Reply
JohnNichols
Valued Contributor III
331 Views

Screenshot 2024-01-10 143828.png

 

Screenshot 2024-01-10 145612.png

 

Screenshot 2024-01-10 144718.png

is only to about E15, certainly if the number is a = 1e16, then the math is a + 1 = a, only if exp is less than 16 is a+ 1 = b where a and b are distinct. 

Sorry just bored and waiting for a download.  

 

0 Kudos
Reply