standards/143358: [libm] nearbyint(3) raises spurious inexact exception

Alexander Best arundel at
Tue Nov 23 23:50:11 UTC 2010

The following reply was made to PR standards/143358; it has been noted by GNATS.

From: Alexander Best <arundel at>
To: bug-followup at
Subject: Re: standards/143358: [libm] nearbyint(3) raises spurious inexact exception
Date: Tue, 23 Nov 2010 23:42:05 +0000

 this is what bruce evans wrote concerning this issue.
 ----- Forwarded message from Bruce Evans <brde at> -----
 Date: Tue, 16 Nov 2010 06:01:06 +1100 (EST)
 From: Bruce Evans <brde at>
 To: Alexander Best <arundel at>
 cc: Bruce Evans <brde at>, Ulrich Spoerlein <uqs at>,
         das at
 Subject: Re: svn commit: r215237 - head/lib/msun/src
 [Cc trimmed]
 On Mon, 15 Nov 2010, Alexander Best wrote:
 >if you are interested in solving two more msun mysteries, you might want to
 >have a look at #PR kern/133583 and standards/143358.
 I had already debugged #143358.  The mail wasn't sent to gnats.
 >From bde at Sun Jan 31 02:20:33 2010 +1100
 Date: Sun, 31 Jan 2010 02:20:30 +1100 (EST)
 From: Bruce Evans <brde at>
 X-X-Sender: bde at
 To: gavin at
 cc: freebsd-amd64 at, freebsd-standards at, das at
 Subject: Re: standards/143358: nearbyint raises spurious inexact exception
 In-Reply-To: <201001301251.o0UCpSEP077706 at>
 Message-ID: <20100131014341.J78095 at>
 References: <201001301251.o0UCpSEP077706 at>
 MIME-Version: 1.0
 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
 Status: O
 X-UID: 1287
 On Sat, 30 Jan 2010 gavin at wrote:
 >Synopsis: nearbyint raises spurious inexact exception
 >Note that a comment in the function itself in lib/msun/src/s_nearbyint.c
 >does also suggest that this PR is valid, "We save and restore the
 >floating-point environment to avoid raising an inexact exception."  I've
 >also verified Solaris 10, Linux and FreeBSD 7.2 show the expected behaviour.
 This seems to be a bug in gcc-4.2, or perhaps a bug in the inline asms.
 gcc-4.2 still works with -O0, but with -O it removes the entire fesetenv()
 in nearbyint().  The fegetenv() isn't removed though its result is never
 used.  I didn't get anywhere good trying to fix this, but I got to the
 following worse place of interest: after replacing the fesetenv(&env) by
 fesetenv(&xenv) where xenv is an invalidly initialized global variable
 (all 0's), the fegetenv(&env) corrupted the current environment (looks
 a bit like xenv was used to initialize the current environment).
 Removing fesetenv() in other contexts would give larger bugs.
 Note that it is the libary that must be compiled with -O0 to avoid this
 ----- End forwarded message -----

More information about the freebsd-standards mailing list