From owner-freebsd-numerics@FreeBSD.ORG Wed Jun 19 19:54:06 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 B6C932DA for ; Wed, 19 Jun 2013 19:54:06 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-pa0-x236.google.com (mail-pa0-x236.google.com [IPv6:2607:f8b0:400e:c03::236]) by mx1.freebsd.org (Postfix) with ESMTP id 9453A1BAC for ; Wed, 19 Jun 2013 19:54:06 +0000 (UTC) Received: by mail-pa0-f54.google.com with SMTP id kx10so5481943pab.41 for ; Wed, 19 Jun 2013 12:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:from:date:message-id:subject:to:content-type; bh=qWoiqpYfkvP/tAaOeJk27O6a1Xlln9WZnIkVu+cqThU=; b=oOq+5OYywWaaGAfI0yybQUDgQzvP2niYQQ6RW96l9lllImxgddEYrMboXV7KVgbkqm 7pBUmenUjahv6gGqNltrTvaeOdpiqturfVfdP23xMFaHKH15MuC6enZ0qIbr0LzVYPsu CrWoHe+9y0PS70JdCDfmLpu7lo9AeZrl7tvP0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type :x-gm-message-state; bh=qWoiqpYfkvP/tAaOeJk27O6a1Xlln9WZnIkVu+cqThU=; b=NVE+BjYTB9AH1+O4wuFVH6Y6CbTs4veOEwJupePAVDI9CYs2aDptWuStckt/UsL8Ot //fmHyEzt95/xHKCT9XCc8xZ8zZtcoAHn5f6qc+1jr6SHiLNSqc+NJ2u1z2tRmkgyB5z QIXldbY6zJdeUrpkJxLGD9e0/TgZx9TjF81rOkMcbvzmLqv+Xoi8NN0lIUvHiybmHg2z 4KyBrBLGIOo+7ZAh3zLq8FeKJ7DSiLeugoANMo+GbPjvwJqaMMl84gZbt7++G6HyZysg cHkCEShwO1kpvq+CMKbmKngCwXsuDWrFlcVQfGBAdtWr0RE5gNhdQGryTMoNg8YtkCNp Ti7g== X-Received: by 10.66.240.70 with SMTP id vy6mr8415608pac.70.1371671646375; Wed, 19 Jun 2013 12:54:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.70.45.33 with HTTP; Wed, 19 Jun 2013 12:53:35 -0700 (PDT) From: Eitan Adler Date: Wed, 19 Jun 2013 21:53:35 +0200 Message-ID: Subject: operation precedence bug: lib/msun/src To: freebsd-numerics@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQlil8OYbEVztpEJFHRVvzV3dPlJJjrIMXNUaODFXhKgsUx4TUanD26Ti0vPg25KWm9MkQR3 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: Wed, 19 Jun 2013 19:54:06 -0000 Does the following look correct? commit 8314bb5309d86bd780c49549eb6a6c43cc9f2fff Author: Eitan Adler Date: Wed Jun 19 21:51:05 2013 +0200 Fix operation precedence bug: != comes before ^ so add required parens Reported by: swildner@DragonFlyBSD.org Reviewed by: swildner@DragonFlyBSD.org Reviewed by: dim, freebsd-numerics@ diff --git a/lib/msun/src/s_fma.c b/lib/msun/src/s_fma.c index 452bece..406ff47 100644 --- a/lib/msun/src/s_fma.c +++ b/lib/msun/src/s_fma.c @@ -117,7 +117,7 @@ add_and_denormalize(double a, double b, int scale) if (sum.lo != 0) { EXTRACT_WORD64(hibits, sum.hi); bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1; - if (bits_lost != 1 ^ (int)(hibits & 1)) { + if (bits_lost != (1 ^ (int)(hibits & 1))) { /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */ EXTRACT_WORD64(lobits, sum.lo); hibits += 1 - (((hibits ^ lobits) >> 62) & 2); diff --git a/lib/msun/src/s_fmal.c b/lib/msun/src/s_fmal.c index 9271901..ec4cc4d 100644 --- a/lib/msun/src/s_fmal.c +++ b/lib/msun/src/s_fmal.c @@ -113,7 +113,7 @@ add_and_denormalize(long double a, long double b, int scale) if (sum.lo != 0) { u.e = sum.hi; bits_lost = -u.bits.exp - scale + 1; - if (bits_lost != 1 ^ (int)(u.bits.manl & 1)) + if (bits_lost != (1 ^ (int)(u.bits.manl & 1))) sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); } return (ldexp(sum.hi, scale)); -- Eitan Adler