user3531410
user3531410

Reputation: 133

how to overcome integer overflow in fortran 90?

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?

Upvotes: 1

Views: 3216

Answers (1)

innoSPG
innoSPG

Reputation: 4656

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.

Upvotes: 2

Related Questions