Fortran:整数太大而不适合 [英] Fortran: Integer too big for its kind

查看:488
本文介绍了Fortran:整数太大而不适合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个整数设置为小于其最大值的整数,但接收到的错误太大而不适合。为什么是这样?这是一个示例程序。

 程序max_int 

整数,参数:: i32 = selected_int_kind(32)

integer(kind = i32):: my_int

!这种类型的最大整数
print *,huge(my_int)

! b $ b my_int = 100000

!这不,并且出现错误。
!my_int = 1000000000000

print *,my_int

结束程序


解决方案

您需要将 i32 附加到 1000000000000 像这样: 1000000000000_i32 。 gfortran抱怨说这个数字太大而不适合。 1000000000000 是一个短整数,不是超长整数。 1000000000000_i32 是一个超长整数。它不抱怨变量,它抱怨常量。


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

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆