参数类型问题

时间:2015-05-24 14:24:11

标签: casting compiler-errors fortran

为什么我收到以下错误

  d = Atan ( 1_Real32 / 110443_Real32 )
             1
Error: 'x' argument of 'atan' intrinsic at (1) must 
be REAL or COMPLEX

有趣的是,当我使用

时,我没有遇到任何问题
d = Atan ( Real(1,Real32) / Real(110443,Real32) )

2 个答案:

答案 0 :(得分:4)

The value 1_Real32 is an int-literal-constant (R407, Fortran2008 4.4.2.2 5).

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).

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.

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.

答案 1 :(得分:3)

casey's answer是完全正确的,但在回答这个问题时可能需要明确指出一件事。

内在$xml->xpath(//d:ServiceId[.= '123'])接受整数参数并返回默认或指定种类的实数。 <?xml> <feed xmlns:m="" xmlns:d=""> <entry> <content> <m:properties> <d:ServiceId>123</d:ServiceId> <d:ServiceName>Service 1</d:ServiceName> <d:DMA>DMA 1</d:DMAName> <d:Abbreviation>ABC</d:Abbreviation> </m:properties> </content> <content> <m:properties> <d:ServiceId>456</d:ServiceId> <d:ServiceName>Service 2</d:ServiceName> <d:DMA>DMA 2</d:DMAName> <d:Abbreviation>DEF</d:Abbreviation> </m:properties> </content> <content> <m:properties> <d:ServiceId>789</d:ServiceId> <d:ServiceName>Service 3</d:ServiceName> <d:DMA>DMA 3</d:DMAName> <d:Abbreviation>HIJ</d:Abbreviation> </m:properties> </content> </entry> </feed> </xml> 是整数(如果real是整数的有效种类数),1_real32是真实的。