https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96711
--- Comment #10 from B Eggen <bre08 at eggen dot co.uk> ---
I've been experimenting with the suggested work-around
m = anint(y)
This works for larger numbers, even in quad precision, however, it breaks down
a long way before the integer*16 range is exhausted, consider the code below,
which starts with 2^113 and tries to double it, minus 1. The minus 1 is not
taking effect:
-> ./aint_working.e
10384593717069655257060992658440192.0000000000
the next two lines should end in ...83
20769187434139310514121985316880384.0000000000
20769187434139310514121985316880384.0000000000
20769187434139310514121985316880383
The source code is:
program aint_working
! does not work in quad precision (real*16)
! -> echo '2^113' | bc = 10384593717069655257060992658440192
! -> echo '2^114' | bc = 20769187434139310514121985316880384
integer(kind=16) :: i, j, k
integer, parameter :: idp=selected_real_kind(9,99)
integer, parameter :: iqp=selected_real_kind(19,199)
integer, parameter :: i16=selected_int_kind(38)
real(kind=iqp) :: x, y, z
x=10384593717069655257060992658440192.0q0 ! that is 2^113
i=10384593717069655257060992658440192_16 ! as above, but integer
k=20769187434139310514121985316880384_16 ! that is 2^114
write(*,'(1x,f50.10)') x
write(*,*) 'the next two lines should end in ...83'
write(*,*)
y=(x+x)-1.0q0
write(*,'(1x,f50.10)') y
z=(x-1.0q0)+x ! see if this helps
write(*,'(1x,f50.10)') z
j=(i+i)-1_16
write(*,*)
write(*,'(1x,i39)') j ! this is correct result (2^114-1)
stop
end program aint_working
I guess at some point NINT() will be fixed, can anyone suggest a robust
workaround that is valid until 2^127-1 ?
Thanks, Bernd