Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jun 2013 21:53:35 +0200
From:      Eitan Adler <lists@eitanadler.com>
To:        freebsd-numerics@freebsd.org
Subject:   operation precedence bug: lib/msun/src
Message-ID:  <CAF6rxg=7AQ-5qnOu0_neZMG-=xQTL5wjM+t_qopeVN4uxg8g5w@mail.gmail.com>

Next in thread | Raw E-Mail | Index | Archive | Help
Does the following look correct?

commit 8314bb5309d86bd780c49549eb6a6c43cc9f2fff
Author: Eitan Adler <lists@eitanadler.com>
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



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?CAF6rxg=7AQ-5qnOu0_neZMG-=xQTL5wjM+t_qopeVN4uxg8g5w>