program nint_error

  integer :: n, m
  integer(kind=16) :: i, j, nint

  integer, parameter :: idp=selected_real_kind(9,99)
  integer, parameter :: i16=selected_int_kind(38)

  real(kind=idp) :: x, y

  write(*,'(*(g0:" "))') 'i16=', i16
  i=1_16
  x=1.0d0
  do n=1, 128, 1
     j=i-1_16
     y=x-1.0d0
     m=nint(y,i16)
     write(*,'(*(g0:" "))') n, i, x, m
     i=i+i
     x=x+x
     if (m<1) exit
  end do
  
  stop
end program nint_error
