昨天改写一些代码,任务很简单,但改写调试却花了一天半的时间。最后发现这个错误以前也犯过,情形如下:
! 对于如下的模式 do i =1,n temp = function(i) out(i) = temp enddo ! 已知 function(i)只在 log(i)为真时才是非零,为节省计算量,采用了如下形式 do i =1,n if(log(i)) then temp = function(i) endif out(i) = temp enddo
! 却忽略了 funtion(i) 为零时的处理,应在判断时加上对零值的处理 if(log(i)) then temp = function(i) else temp = 0.d0 endif
一定要考虑全面!