how to overcome integer overflow in fortran 90?

微笑、不失礼 提交于 2021-02-11 06:14:31

问题


hi i am having some problem with integer over flow in fortran 90. The maximum range of integer number is 10 digits.but, I want to deal with integer of the range 1E13. So what is the way of avoiding this?


回答1:


define your variable as

   integer(kind=8) :: intVar

To have a portable code, use the function selected_int_kind. In your case

   integer, parameter, k14 = selected_int_kind(14)
   integer(kind=k14) :: intVar

selected_int_kind(r) returns the kind value of the smallest integer type that can represent all values ranging from -10^r (exclusive) to 10^r (exclusive, that is why I used 14). For more details on selected_int_kind, See http://gcc.gnu.org/onlinedocs/gfortran/SELECTED_005fINT_005fKIND.html. Keep it mind that selected_int_kind might return -1, ff there is no integer kind that accommodates the chosen range.



来源:https://stackoverflow.com/questions/23126363/how-to-overcome-integer-overflow-in-fortran-90

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!