|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
程序很简单,计算平方根,返回复数值,结果编译警告三个,说第0个形参与实参类型不对。运行结果说access violation
program main
complex(8) x
x=sqrt1(2.0)
print*, x
end program main
complex(8) function sqrt1(a)
real(8)::x,e=1E-4,p,q,x0=1.0
real(8) a
parameter(N=1E8)
logical::s=.false.
x=abs(a)
p=(x0+x/x0)/2
do i=1,N
q=(p+x/p)/2
if (abs(q-p)<=e) then
s=.true.
exit
else
p=q
endif
enddo
if (s==.false.) then
sqrt=-1
print *,'The Method failed'
return
endif
if (a<0) then
sqrt1=cmplx(0,q)
else
sqrt1=cmplx(q,0)
endif
end function
编译警告:
E:\fortran works\numeric1\test.f90(3) : Warning: In the call to SQRT1, actual argument #0 does not match the type and kind of the corresponding dummy argument.
x=sqrt1(2.0)
---------^
E:\fortran works\numeric1\test.f90(3) : Warning: In the call to SQRT1, there is no actual argument corresponding to the dummy argument A.
x=sqrt1(2.0)
---^
E:\fortran works\numeric1\test.f90(3) : Warning: Routine SQRT1 called with different number and/or type of actual arguments in earlier call - C attribute required if intended.
x=sqrt1(2.0)
---^
test.obj - 0 error(s), 3 warning(s) |
|