From owner-freebsd-numerics@FreeBSD.ORG Fri Jun 28 05:23:48 2013 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 1F90FAD4 for ; Fri, 28 Jun 2013 05:23:48 +0000 (UTC) (envelope-from das@FreeBSD.ORG) Received: from zim.MIT.EDU (50-196-151-174-static.hfc.comcastbusiness.net [50.196.151.174]) by mx1.freebsd.org (Postfix) with ESMTP id AF80212AC for ; Fri, 28 Jun 2013 05:23:47 +0000 (UTC) Received: from zim.MIT.EDU (localhost [127.0.0.1]) by zim.MIT.EDU (8.14.7/8.14.2) with ESMTP id r5S4wUZ6004172; Thu, 27 Jun 2013 21:58:30 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by zim.MIT.EDU (8.14.7/8.14.2/Submit) id r5S4wTwC004171; Thu, 27 Jun 2013 21:58:29 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Date: Thu, 27 Jun 2013 21:58:29 -0700 From: David Schultz To: Eitan Adler Subject: Re: operation precedence bug: lib/msun/src Message-ID: <20130628045829.GA3590@zim.MIT.EDU> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Cc: freebsd-numerics@freebsd.org X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jun 2013 05:23:48 -0000 On Wed, Jun 19, 2013, Eitan Adler wrote: > Does the following look correct? [...] > diff --git a/lib/msun/src/s_fma.c b/lib/msun/src/s_fma.c [...] > - if (bits_lost != 1 ^ (int)(hibits & 1)) { > + if (bits_lost != (1 ^ (int)(hibits & 1))) { No, logical xor is intended: If we lost one bit due to denormalization, we need to adjust if the low bit is 1, and if we lost more than one bit, we need to adjust if the low bit is 0. I apologize for writing 6 lines of code that would take pages to explain. The relevant background (guard and sticky bits) is covered in the following book chapter if you're interested: http://uenics.evansville.edu/~mr56/ece752/AppendixH.pdf