Fortran:整数太大了 [英] Fortran: Integer too big for its kind
本文介绍了Fortran:整数太大了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一个整数设置为小于其最大值的值,但收到一个错误,指出它太大了,不合适.为什么是这样?这是一个示例程序.
I am setting an integer to a value less than its maximum, but receiving an error that it is too big for it's kind. Why is this? Here is a sample program.
program max_int
integer, parameter :: i32 = selected_int_kind(32)
integer(kind = i32) :: my_int
!The largest integer of this kind
print*, huge(my_int)
!This works
my_int = 100000
!This doesn't, and gives an error.
!my_int = 1000000000000
print*, my_int
end program
推荐答案
您需要将 i32
附加到 1000000000000
如下: 1000000000000_i32
.gfortran 抱怨这个数字太大了.1000000000000
是短整数,不是超长整数.1000000000000_i32
是一个超长整数.它不是在抱怨变量,而是在抱怨常量.
You need to append the i32
to 1000000000000
like this: 1000000000000_i32
. gfortran complains that the number is too big for it's kind. 1000000000000
is a short integer, not a super long integer. 1000000000000_i32
is a super long integer. It is not complaining about the variable, it's complaining about the constant.
这篇关于Fortran:整数太大了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文