参数类型问题 [英] Argument Type Problems
问题描述
为什么会收到以下错误
d = Atan ( 1_Real32 / 110443_Real32 )
1
Error: 'x' argument of 'atan' intrinsic at (1) must
be REAL or COMPLEX
$ b b
有趣的是,当我使用
The funny thing is that I get no problems when I use
d = Atan ( Real(1,Real32) / Real(110443,Real32) )
推荐答案
code> 1_Real32 是一个字符常数 (R407,Fortran2008 4.4.2.2 5)。
The value 1_Real32
is an int-literal-constant (R407, Fortran2008 4.4.2.2 5).
要获取真实值,您需要将其更改为 1._Real32
。十进制的存在使其成为一个实数常数(R413,Fortran2008 4.4.2.3 6)。
To get a real value instead you need to change it to 1._Real32
. The presence of the decimal makes it a real-literal-constant (R413, Fortran2008 4.4.2.3 6).
请记住, Real32
在代码中只是一个数字,例如 4
,它只指定一种类型,而不是类型。 1_4
是类型4的整数, 1._4
是类型4的真实。
Remember that Real32
in your code is just a number, e.g. 4
and it only specifies a kind, not a type e.g. 1_4
is an integer of kind 4 and 1._4
is a real of kind 4.
您不会遇到第二个示例中的错误,因为内部 real()
总是返回一个实值,包括当提供一个整数其第一个参数。
You don't encounter the error in the second example because the intrinsic real()
always returns a real value including when supplied an integer as its first argument.
这篇关于参数类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!