Silverfrost Forums

Welcome to our forums

Failure at run-time with format F when using real KIND=3

1 Aug 2024 11:12 #31449

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?

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=(B-A)*FLOAT(I)/FLOAT(N)
  WRITE(*,9000) I,T
END DO
9000 FORMAT(1X,I4,3X,F7.2)
END PROGRAM RUNGE
1 Aug 2024 12:11 #31450

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

2 Aug 2024 3:01 #31451

This is a very strange error ! The following does not show the problem ?

  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=(B-A)*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 ?

2 Aug 2024 10:09 #31453

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 ?

  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=(B-A)*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 1993-2024]

Even with Release, Win32 it crashes at i=19

The following change skips the error, do n = 994,1004 if ( n == 1000 ) cycle

??

2 Aug 2024 10:47 #31454

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:

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
2 Aug 2024 5:55 #31455

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

3 Aug 2024 12:34 #31456

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 (80-bit) number, since I can only use 64-bit integers (KIND=4) as targets with the TRANSFER method in FTN95?

5 Aug 2024 4:47 #31457

This should work. This causes an error in both Checkmate and Release.

	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+indx-1),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
5 Aug 2024 5:25 #31458

FWIW: Fortran 9.02.00

6 Aug 2024 11:38 (Edited: 20 Aug 2024 12:12) #31461

Bill Thanks for the method of showing the physical representation of a 80-bit 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.

7 Aug 2024 3:07 #31462

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

19 Aug 2024 8:25 #31476

This failure has now been fixed for the next release of salflibc.dll.

20 Aug 2024 8:34 #31495

Paul Thank you for this.

Please login to reply.