Attached patch fixes PR31202 by correcting the code generated for calls to the intrinsic NINT (and ANINT). Instead of adding 0.5 and rounding by casting into an integer, we simply call the lround (or llround) functions. A fallback implementation of these functions is provided for libgfortran. I've bootstrapped and regtested on x86_64-linux, but I'd be glad if someone with a platform without full C99 support, and especiall lround, could test it. I once had access to a sparc-solaris2.9, which fulfilled these criteria, but not more. OK for mainline? :ADDPATCH 31202: