Code in the C nearbyintf and possibly other nearbyint implementations can be scheduled by the compiler so arithmetic that raises the "inexact" exception runs after the fesetenv intended to clear that exception. http://sourceware.org/ml/libc-alpha/2013-05/msg00720.html gives an example I can reproduce on x86_64 with --disable-multi-arch (otherwise the SSE4.1 version gets used).
Fixed for 2.18 by: commit 3e694268750d51acc6a68b0ee7ded25a52902c20 Author: Joseph Myers <joseph@codesourcery.com> Date: Sun May 19 18:40:25 2013 +0000 Fix nearbyint scheduling of arithmetic past fesetenv (bug 15490).