Description
When compiling stdlib using NAG Fortran compiler 7.0 for Windows on Windows 10, it terminates compiling with the error "Integer (KIND=3) overflow" (KIND=3 corresponds to int32 in NAG Fortran).
Errors are detected in to_bytes_i4
in stdlib_io_npy_save.fypp and in get_descriptor
in stdlib_io_npy_load.fypp .
In the procedures, the integer literal 2**32
is used in expressions as below:
stdlib/src/stdlib_io_npy_save.fypp
Lines 63 to 66 in 8eaa778
stdlib/src/stdlib_io_npy_load.fypp
Lines 135 to 143 in 8eaa778
I guess that 2**24
is probably correct instead of 2**32
.
I have understood that to_bytes_i4
converts an integer to a byte string by converting a 32 bit decimal integer to a base-256 number and then to four ASCII characters.
In this case, the power of base number (=256) at each position are (256**0
, 256**1
, 256**2
, 256**3
), corresponding to (2**0
, 2**8
, 2**16
, 2**24
).
This consideration does not cover negative integers, but if my understanding is correct, the concerning expressions can be modified as follows:
str = achar(mod(val, 256**1)) // &
& achar(mod(val, 256**2) / 256**1) // &
& achar(mod(val, 256**3) / 256**2) // &
& achar(val / 256**3)
and
if (major > 1) then
header_len = ichar(buf(1)) &
& + ichar(buf(2)) * 256**1 &
& + ichar(buf(3)) * 256**2 &
& + ichar(buf(4)) * 256**3
else
header_len = ichar(buf(1)) &
& + ichar(buf(2)) * 256**1
end if
If using 2**32
is a trick to handle negative integers, I need another solution to compile stdlib using NAG Fortran compiler.