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)
的 integer算术完成计算的一部分时,便会出现问题.>.该类型的上限为 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屋!