作者sea010461 (sin of bleed)
看板Fortran
标题[问题]关於arithmetic overflow
时间Mon Sep 30 10:27:52 2013
最近开始学习写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
1F:推 terryys:10**12是一个整数,所以会overflow 09/30 10:53
2F:→ terryys:可以用9.46e12 或者9.46*10.0**12之类的,只要不是整数 09/30 10:55
3F:→ sea010461:感谢感谢!!成功了 09/30 11:02