主题:大数吃小数问题!
对于下面这段程序,本来当n取5000以上时,最后会出现大数吃小数的问题,但这里却不会。为什么,难道function的结果存储与一般的数据存储部一样吗?谢谢!
---------------------------------------------------------------
program test
implicit none
integer::n
real,external::funx
print *,'请输入要计算funx函数的次数:'
read(*,*) n
call calculate(n,funx)
end program test
subroutine calculate(n,fun)
implicit none
integer::n,i
real::time1,time2,s
Real::fun
s=0.
call cpu_time(time1)
do i=1,n
s=fun(n)+s
end do
call cpu_time(time2)
write(*,'(1X,"计算结果=",E10.5)') s
write(*,'(1X,"计算时间=",F10.2)') time2-time1
end subroutine calculate
real function funx(n)
implicit none
integer::n,i
funx=0.
do i=1,n
funx=funx+sqrt(2.)
end do
end function funx
---------------------------------------------------------------
program test
implicit none
integer::n
real,external::funx
print *,'请输入要计算funx函数的次数:'
read(*,*) n
call calculate(n,funx)
end program test
subroutine calculate(n,fun)
implicit none
integer::n,i
real::time1,time2,s
Real::fun
s=0.
call cpu_time(time1)
do i=1,n
s=fun(n)+s
end do
call cpu_time(time2)
write(*,'(1X,"计算结果=",E10.5)') s
write(*,'(1X,"计算时间=",F10.2)') time2-time1
end subroutine calculate
real function funx(n)
implicit none
integer::n,i
funx=0.
do i=1,n
funx=funx+sqrt(2.)
end do
end function funx