gfortran 编译器错误:求幂结果超出 INTEGER(4) 的范围 [英] gfortran compiler Error: result of exponentiation exceeds the range of INTEGER(4)
问题描述
我在 fortran 中有这一行,但标题中出现编译器错误.dFeV 是一维实数数组.dFeV(x)=R1*5**(15) * (a**2) * EXP(-(VmigFe)/kbt)
作为记录,变量名是继承的,不是我的错.我认为这是一个问题,因为没有内存空间来计算右侧的值,然后我将其存储在左侧作为真实值(这将有足够的空间),但我不知道如何为此分配更多空间计算.
I have this line in fortran and I'm getting the compiler error in the title. dFeV is a 1d array of reals.
dFeV(x)=R1*5**(15) * (a**2) * EXP(-(VmigFe)/kbt)
for the record, the variable names are inherited and not my fault. I think this is an issue with not having the memory space to compute the value on the right before I store it on the left as a real (which would have enough room), but I don't know how to allocate more space for that computation.
推荐答案
问题出现是因为您的计算的一部分是使用 integer(4)
整数算术 完成的>.该类型的上限为 2^31-1 = 2147483647
而您的中间结果 5^15 = 30517578125
稍大(感谢@evets 评论).
The problem arises as one part of your computation is done using integer arithmetic of type integer(4)
.
That type has an upper limit of 2^31-1 = 2147483647
whereas your intermediate result 5^15 = 30517578125
is slightly larger (thanks to @evets comment).
正如您的问题所指出的:您将结果保存在一个实变量中.因此,您可以使用 real
数据类型:5.0**15
计算该指数.您的公式最终将如下所示
As pointed out in your question: you save the result in a real variable.
Therefor, you could just compute that exponentiation using real
data types: 5.0**15
.
Your formula will end up like the following
dFeV(x)= R1 * (5.0**15) * (a**2) * exp(-(VmigFe)/kbt)
请注意,integer(4)
不必是每个处理器的相同实现(感谢@IanBush).这只是意味着对于某些特定机器,上限可能与 2^31-1 = 2147483647
不同.
Note that integer(4)
need not be the same implementation for every processor (thanks @IanBush).
Which just means that for some specific machines the upper limit might be different from 2^31-1 = 2147483647
.
这篇关于gfortran 编译器错误:求幂结果超出 INTEGER(4) 的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!