1

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.