【发布时间】:2016-03-03 06:25:56
【问题描述】:
我现在正在为某个迭代运行一个程序。时间步长为 0.01。我想在达到特定时间时写一些信息。例如:
program abc
implicit none
double precision :: time,step,target
integer :: x
time = 0.d0
step = 0.01
target = 5.d0
do x = 1,6000
time = time + step
"some equations here to calculate the model parameters"
if(time.eq.target)then
write(*,*) "model parameters"
endif
enddo
但是,“时间”永远不会等于 1.0 或 2.0 等。它显示为“0.999999866”而不是“1.0”和“1.99999845”而不是“2.0”。
虽然我可以使用整数“x”来定义何时写入信息,但我更喜欢使用时间步长。另外,我可能想更改时间步长(0.01/0.02/0.05/etc)或目标(5.0/6.0/8.0/etc)。
有谁知道如何解决这个问题?先谢谢了。
【问题讨论】:
-
if(x.eq.nint(target/step))