odd compiler complaints with large numbers
- From: Ron Ford <ron@xxxxxxxxxxxxxxx>
- Date: Thu, 28 Aug 2008 23:54:43 -0600
I don't know what to think of the data I see with silverfrost. The largest
integer that executes with this little program is 2.1 billion, which is a
few orders of magnitude short of the 13 that it promises to deliver:
implicit none
integer, parameter :: i13 = selected_int_kind(13)
integer(i13), parameter:: trials = 2100000000
integer(i13):: i
integer:: counter
real:: harvest, ratio
CALL init_random_seed
counter = 0
do i = 1, trials
call random_number(harvest)
if (harvest ==0.50) then
print *, i, harvest
counter = counter + 1
end if
end do
ratio= real(trials)/real(counter)
print *, "frequency was ", ratio
contains
SUBROUTINE init_random_seed()
INTEGER :: i, n, clock
INTEGER, DIMENSION(:), ALLOCATABLE :: seed
CALL RANDOM_SEED(size = n)
print *, "n=", n
ALLOCATE(seed(n))
CALL SYSTEM_CLOCK(COUNT=clock)
print *, "clock=", clock
seed = clock + 37 * (/ (i - 1, i = 1, n) /)
CALL RANDOM_SEED(PUT = seed)
print *, "seed= ", seed
DEALLOCATE(seed)
END SUBROUTINE
end program
Typical output is:
2063773121 0.500000
2070779538 0.500000
2090015224 0.500000
2093563823 0.500000
frequency was 1.590909E+07
If I ask for a trial size of 2.2 billion, I get:
error 217 - INTEGER(KIND=3) constant out of range
That's crazy, because the s.i.k. for 13 is 4.
If I add the _i13 tag to this constant, the compiler error is:
error 637 - Internal compiler error - floating point exception
I'd be curious how others' mileage fares with large integers.
--
We must respect the other fellow's religion, but only in the sense and to
the extent that we respect his theory that his wife is beautiful and his
children smart. 5
H. L. Mencken
.
- Follow-Ups:
- Re: odd compiler complaints with large numbers
- From: Mark Stevens
- Re: odd compiler complaints with large numbers
- Prev by Date: Re: Project dependency of CVF 6.6c
- Next by Date: Re: Surprise
- Previous by thread: Free Fortran compiler for PowerPC Mac?
- Next by thread: Re: odd compiler complaints with large numbers
- Index(es):