cmplx(x,y)出来的结果为complex的默认精度,不管x,y的精度是多少
从fortran wiki (http://fortranwiki.org/fortran/show/cmplx)上看cmplx函数有三种形式:
1.cmplx(x). x可以是interger、real、complex, 结果为complex的默认精度
2.cmplx(x,y). x可以是interger、real,y为integer、real,结果为complex的默认精度
3.cmplx(x,y,kind). x可以是interger、real,y为integer、real,kind为interger,结果精度为kind
complex(kind=n) 等价于complex*2n。例如:
complex(4) 等价于 complex*8
complex(8) 等价于 complex*16
complex(16) 等价于 complex*32
complex默认为complex(real, real)类型,real受编译器的real影响。
-------------------------------------------------------------------------------------------------------------------------
from: http://fortranwiki.org/fortran/show/cmplx
Description
cmplx(x [, y [, kind]])
returns a complex number where x
is converted to the real component. If y
is present it is converted to the imaginary component. If y
is not present then the imaginary component is set to 0.0. If x
is complex then y
must not be present.
Standard
FORTRAN 77 and later
Class
Syntax
result = cmplx(x [, y [, kind]])
Arguments
x
- The type may beinteger
,real
, orcomplex
.y
- (Optional; only allowed ifx
is notcomplex
.) May beinteger
orreal
.kind
- (Optional) Aninteger
initialization expression indicating the kind parameter of the result.
Return value
The return value is of complex
type, with a kind equal to kind
if it is specified. If kind
is not specified, the result is of the default complex
kind, regardless of the kinds of x
and y
.
Example
program test_cmplx
integer :: i = 42
real :: x = 3.14
complex :: z
z = cmplx(i, x)
print *, z, cmplx(x)
end program test_cmplx
-------------------------------------------------------------------------------------------------------------------------
from:https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-developer-guide-and-reference/top/language-reference/data-types-constants-and-variables/intrinsic-data-types/complex-data-types.html
-----------------------------------------------------------
本文来自博客园,作者:小厨房,转载请注明原文链接:https://www.cnblogs.com/erichf/p/12909794.html,否则视为侵权
如有疑问,请站内留言 或加 QQ:②⑨⓪②② ⑦③⑦⑨
-----------------------------------------------------------