- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm seeing a strange behaviour from int64 integer. Following code:
use iso_fortran_env implicit none integer (int64) :: i i=2**32-2 write (*,*) "i, btest (i,0)" , i, btest (i,0) write (*,*) "i, btest (i,31)" , i, btest (i,31) write (*,*) "i, btest (i,32)" , i, btest (i,32) write (*,*) "i, btest (i,33)" , i, btest (i,33) write (*,*) "huge (i)" , huge (i)
returns:
i, btest (i,0) -2 F
i, btest (i,31) -2 T
i, btest (i,32) -2 T
i, btest (i,33) -2 T
huge (i) 9223372036854775807
which shows that it calculates 2^32-2 as -2. Whereas limit on int64 is 9223372036854775807 that is way bigger than 2^32!
Wonder if I'm doing something wrong!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The expression on the right hand side of the assignment to i is not using 64 bit integers.
Consider the difference between the print statements in the following:
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 IMPLICIT NONE PRINT *, 2**32-2 PRINT *, 2_INT64**32-2 END
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The expression on the right hand side of the assignment to i is not using 64 bit integers.
Consider the difference between the print statements in the following:
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 IMPLICIT NONE PRINT *, 2**32-2 PRINT *, 2_INT64**32-2 END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Ian. the problem is fixed!

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page