I have a simple question, but I can't figure out the answer. Does anyone know why the following program outputs b=-589934592 instead of b=8000000000 ? This must be related to the product of a*a*a causing an integer overflow. I want to have intermediate variables be integer(kind=4) and the result stored in integer(kind=8).
program test_integer8 implicit none integer(kind=4) a integer(kind=8) b a = 2000 b = a*a*a ! How do you fix this line? write(*,*) 'b = ', b stop end program test_integer8