casting - 参数类型问题

标签 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) )

最佳答案

1_Real32是整数常量(R407,Fortran2008 4.4.2.2 5)。

要获取真实值,您需要将其更改为1._Real32。小数的存在使它成为实数常量(R413,Fortran2008 4.4.2.3 6)。

请记住,您代码中的Real32只是一个数字,例如4,它仅指定一种类型,而不指定类型,例如1_4是类型4的整数,而1._4是类型4的实数。

在第二个示例中,您不会遇到错误,因为内在的real()始终返回一个实数值,包括在提供整数作为其第一个参数时。

关于casting - 参数类型问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30424557/

相关文章:

在普通的旧 C 中抛弃 volatile

c# - 我不明白为什么第一个正确,但是第二个失败

JAVA - 无法编译

compilation - 子程序中未定义语句的Fortran问题

integer - 在 fortran 中访问无符号整数值

java - 如何使用 Jackson 将 Object 类发送到服务器?

c++ - boost::lexical_cast<int> ("-138.8468953457983248") 抛出异常

c - 错误 : Assignment makes pointer from Integer without a cast. .. 在 C 程序中

c++ - LNK2038 : mismatch detected for 'boost_log_abi' : value 'v2s_mt_nt5' doesn't match value 'v2s_mt_nt6'

python - Cython、C 和 Fortran