這個程式,顯示了 幾點報告
一 從 1 + 2 + ... + 13億
大概花費的時間是 5.8秒
二 時間的計算,有最小的精確度問題,
小於 0.016秒的時間 無法計算
三 整數有其一定的範圍,加法的答案超過 21億
會出現負值
這些問題,將來有需要的時候,會繼續深入研究
[pre]
! file: VF26.F90
! include 'sj-01.inc'
! -----------------------------------------------
subroutine time1(t1)
implicit none
integer t1
! values (5) The hour of the day (range 0 to 23) - local time
! values (6) The minutes of the hour (range 0 to 59) - local time
! values (7) The seconds of the minute (range 0 to 59) - local time
! values (8) The milliseconds of the second (range 0 to 999) - local time
INTEGER DATE_TIME(8)
CHARACTER (LEN= 12) REAL_CLOCK(3)
CALL DATE_AND_TIME(REAL_CLOCK (1), REAL_CLOCK (2), &
REAL_CLOCK (3), DATE_TIME)
! -----------------------------------------------
t1= date_time(5) !hour
t1= t1*60 + date_time(6) !minutes
t1= t1*60 + date_time(7) !seconds
t1= t1*1000 + date_time(8) !milliseconds
end ! of time1()
! -----------------------------------------------
subroutine time2(t1, dt)
integer t1, t2
real dt
call time1(t2)
dt= (t2 - t1)/(1000.0)
! dt must >= 0.0
if (dt < 0.0) then
dt= dt + 1.0*24.0*60.0*60.0
end if
end ! of time2()
! -----------------------------------------------
! begin of main()
implicit none
integer t1, no, sum, i
real dt
no= 10
do while(no > 0)
call time1(t1)
sum= 0
do i=1, no
sum= sum + i
end do
call time2(t1, dt)
if (dt > 0.0) then
write(*, '(1x, A4, 2I12, F10.6)')'*** ', no, sum, dt
else
write(*, '(1x, A4, 2I12, F10.6)')' ', no, sum, dt
end if
no= no*2
end do
end ! of main()
! end of file
[/pre]
沒有留言:
張貼留言