I am trying to do the following simple assignment in Fortran to a 8 byte integer:
integer(kind=8) :: a
a = 30 * 1000000000
print *,a
However, when I print the value I get the following output:
-64771072
Which seems like either the print
or the calculation 30 * 1000000000
is being done with 4 bytes.
- Is the problem located in the assignment of the variable or in the print -or elsewhere-?
- How can I fix it?
- Is it dependent on a specific Fortran standard?
I am using flang
in a 64 bits FreeBSD system in case it is relevant.
Edit:
As per comments suggestion I have downloaded kindfind.f90
and executed it. This is the output. My understanding is that in my compiler, kind=8 shall provide a 8 bytes as per program description (see here).
$ ./a.out
!---------------------------------------------------------!
! !
! KINDFINDER !
! !
! KIND Search & Evaluation for !
! FloatingPoint and Integer Types !
! of the local Fortran Compiler !
! !
! Author: Werner W Schulz (C) 1998 !
! (email: wws20@cam.ac.uk) !
! !
! !
! FloatingPoint Model Parameters: !
! Kind Precision Range Name !
! 4 6 37 Single !
! 8 15 307 Double !
! !
! !
! Integer Model Parameters: !
! Kind Range Name !
! 1 2 Int_01 !
! 2 4 Int_02 !
! 4 9 Int_Def !
! 8 18 Int_08 !
! !
! !
! !
! NOTE: !
! KindFinder has generated a Programme and a Module in !
! !
! NumericModel.f90 !
! Fortran_Kind_Module.f90 !
! !
! that will compute and display the Numerical Parameters !
! of the various INTEGER & FLOATING POINT Types !
! as specified by Fortran and the local Compiler. !
! The ModuleFile is can be used elsewhere. !
! !
! All Code is compatible with the Fortran Subsets and !
! should be able to run on any Fortran90-conforming !
! Compiler including F and Elf90. !
! !
! NOTE: !
! Possible KIND Values for LOGICAL or CHARACTER Types !
! must be obtained in the local Fortran Reference Manual !
! !
!---------------------------------------------------------!
Warning: ieee_inexact is signaling
FORTRAN STOP
$