
forums.silverfrost.com Welcome to the Silverfrost forums

View previous topic :: View next topic 
Author 
Message 
jlb
Joined: 21 Oct 2020 Posts: 57

Posted: Thu Aug 01, 2024 12:12 pm Post subject: Failure at runtime with format F when using real KIND=3 


The following program, compiled with FTN95 v. 9.03.0.0 Win32, raises an exception (Invalid floating point operation) at runtime for i=19.
This error doesn't occur if KIND=2 is used for the real variables or F7.3 instead of F7.2 in the 9000 FORMAT.
Am I missing an obvious pitfall in this case?
Code:  PROGRAM RUNGE
IMPLICIT NONE
INTEGER :: I, N
REAL(KIND=3) :: A, B, T
A=0.0
B=5.0
N=1000
DO I=1,N
T=(BA)*FLOAT(I)/FLOAT(N)
WRITE(*,9000) I,T
END DO
9000 FORMAT(1X,I4,3X,F7.2)
END PROGRAM RUNGE 


Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7967 Location: Salford, UK

Posted: Thu Aug 01, 2024 1:11 pm Post subject: 


There appears to be a problem with F7.2 for extended precision in this context but G7.2 seems to work OK. 

Back to top 


JohnCampbell
Joined: 16 Feb 2006 Posts: 2567 Location: Sydney

Posted: Fri Aug 02, 2024 4:01 am Post subject: 


This is a very strange error !
The following does not show the problem ?
Code:  PROGRAM RUNGE
IMPLICIT NONE
INTEGER :: I, N
REAL(KIND=3) :: A, B, T
A=0.0
B=5.0
N=1001 ! 35 ! 1000
DO I=1,N
T=(BA)*FLOAT(I)/FLOAT(N)
WRITE(*,9000) I,T
END DO
9000 FORMAT(1X,I4,3X,F7.2)
END PROGRAM RUNGE 
N = 35 or N=1001 work ok, but why not N=1000 ? 

Back to top 


JohnCampbell
Joined: 16 Feb 2006 Posts: 2567 Location: Sydney

Posted: Fri Aug 02, 2024 11:09 am Post subject: 


This shows how unique this problem might be.
The following variant shows there is something special about N = 1000 ; i = 19 ?
Does anyone know the reason for the problem with this ?
Code:  PROGRAM RUNGE
IMPLICIT NONE
INTEGER :: I, N
REAL(KIND=3) :: A, B, T
A=0.0
B=5.0
do n = 4,1004
! N=1000 ! 35 ! 1000
DO I=1,N
T=(BA)*FLOAT(I)/FLOAT(N)
WRITE(*,9000) I,T
END DO
end do
9000 FORMAT(1X,I4,3X,F7.2)
END PROGRAM RUNGE 
I am running using PLATO with Checkmate, Win32
[FTN95/x64 Ver. 9.03.0.0 Copyright (c) Silverfrost Ltd 19932024]
Even with Release, Win32 it crashes at i=19
The following change skips the error,
do n = 994,1004
if ( n == 1000 ) cycle
?? 

Back to top 


jlb
Joined: 21 Oct 2020 Posts: 57

Posted: Fri Aug 02, 2024 11:47 am Post subject: 


Paul
A similar error occurs with N=10000 or 100000 or 1000000 and G7.2 at I=199
John
Thanks for confirming the bug. A similar error occurs with N=10000 and F7.2 at I=189 (not 199!).
Neither the DO loop nor the reals A and B are needed, the reproducer can be reduced to the following:
Code:  PROGRAM RUNGE
IMPLICIT NONE
INTEGER :: I, N
REAL(KIND=3) :: T
I=95
N=1000
T=FLOAT(I)/FLOAT(N)
WRITE(*,9000) I,T
9000 FORMAT(1X,I4,3X,F7.2)
END PROGRAM RUNGE 


Back to top 


wahorger
Joined: 13 Oct 2014 Posts: 1222 Location: Morrison, CO, USA

Posted: Fri Aug 02, 2024 6:55 pm Post subject: 


No error if you use dble(i)/dble(n).
However, the value displayed for the floating point value is still all ******'s.
The hexadecimal of this is interesting as a repeating pattern:
C28F5C28F5C28F5C 

Back to top 


jlb
Joined: 21 Oct 2020 Posts: 57

Posted: Sat Aug 03, 2024 1:34 pm Post subject: 


Bill
I still get the same error with DBLE(I)/DBLE(N) using FTN95 version 9.03.0.0 Win32.
Do you have an easy way to get the full hexadecimal "physical" representation of a KIND=3 real (80bit) number, since I can only use 64bit integers (KIND=4) as targets with the TRANSFER method in FTN95? 

Back to top 


wahorger
Joined: 13 Oct 2014 Posts: 1222 Location: Morrison, CO, USA

Posted: Mon Aug 05, 2024 5:47 pm Post subject: 


This should work. This causes an error in both Checkmate and Release.
Code: 
PROGRAM RUNGE
IMPLICIT NONE
INTEGER :: I, N
integer (KIND=4):: k=0
integer(7):: my_loc,indx
REAL (kind=3) :: T
I=95
N=1000
t=0.0
T=FLOAT(I)/FLOAT(N)
my_loc = loc(t)
! print *,my_loc ! decimal
write(*,9002)my_loc,(core1(my_loc+indx1),indx=1,10)
WRITE(*,9000) I,T
9000 FORMAT(1X,I4,3X,F7.2)
9001 format(z20.20)
9002 format('Start Addr=',z8.8,': ',10z2.2)
END PROGRAM RUNGE



Back to top 


wahorger
Joined: 13 Oct 2014 Posts: 1222 Location: Morrison, CO, USA

Posted: Mon Aug 05, 2024 6:25 pm Post subject: 


FWIW: Fortran 9.02.00 

Back to top 


jlb
Joined: 21 Oct 2020 Posts: 57

Posted: Tue Aug 06, 2024 12:38 pm Post subject: 


Bill
Thanks for the method of showing the physical representation of a 20bit real number. I had all the knowledge to do it myself, as you kindly gave me a workaround for C_F_POINTER some time ago, but unfortunately I didn't recover the trick. Sorry for that and thanks again for your help. 

Back to top 


wahorger
Joined: 13 Oct 2014 Posts: 1222 Location: Morrison, CO, USA

Posted: Wed Aug 07, 2024 4:07 pm Post subject: 


No worries! That's what this forum is for, helping others! 

Back to top 




You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
