[問題]關於arithmetic overflow
最近開始學習寫fortran照著書上打入某個fortran
用gfortran compile給出錯誤訊息
------------------------
ch0504_2.f90:5.38:
real , parameter :: Light_Year=9.46*10**12
1
Error: Arithmetic overflow at (1)
ch0504_2.f90:17.28:
Light_minute = Light_Year/(365.25 * 24.0 * 60.0)
1
--------------------------
可是用ifort compile會過。
讓我很困惑,同樣的寫法,用不一樣的compiler給出不一樣的結果,
要用哪種寫法才不會發生這樣的事呢?
書上的code如下
program ch0504
implicit none
real :: Light_Minute, Distance, Elapse
integer :: Minute, Second
real , parameter :: Light_Year=9.46*10**12
! Light_year : Distance travelled by light
! in one year in km
! Light_minute : Distance travelled by light
! in one minute in km
! Distance : Distance from sun to earth in km
! Elapse : Time taken to travel a
! distance (Distance) in minutes
! Minute : integer number part of elapse
! Second : integer number of seconds
! equivalent to fractional part of elapse
!
Light_minute = Light_Year/(365.25 * 24.0 * 60.0)
Distance = 150.0 * 10 ** 6
Elapse = Distance / Light_minute
Minute = Elapse
Second = (Elapse - Minute) * 60
print *,' Light takes ' , Minute,' Minutes'
print *,' ' , Second,' Seconds'
print *,' To reach the earth from the sun'
end program ch0504
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 128.138.41.222
推
09/30 10:53, , 1F
09/30 10:53, 1F
→
09/30 10:55, , 2F
09/30 10:55, 2F
→
09/30 11:02, , 3F
09/30 11:02, 3F
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章