Module Name:    src
Committed By:   gdt
Date:           Fri Sep 20 22:45:15 UTC 2024

Modified Files:
        src/lib/libm/src: s_remquo.c

Log Message:
libm/remquo: Fix bug where remquo returned wrong sign of quo

ISO C requires that quo be congruent to the quotient mod 2^k and have
a particular sign.  The current code can return 0 when it should be
negative.

Because the code chooses k=31 (for the requirement of congruence
modulo 2^k), the only value available (in ILP32 or LP64) that is
negative and congruent to 0 is 0x80000000.  In the specific case of
wanting "-0", return 0x80000000.

Resolves t_remquo test failure.

\todo pullups
\todo check/fix remquof and remquol


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libm/src/s_remquo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libm/src/s_remquo.c
diff -u src/lib/libm/src/s_remquo.c:1.3 src/lib/libm/src/s_remquo.c:1.4
--- src/lib/libm/src/s_remquo.c:1.3	Fri Sep 20 18:08:32 2024
+++ src/lib/libm/src/s_remquo.c	Fri Sep 20 22:45:15 2024
@@ -156,5 +156,12 @@ fixup:
 	SET_HIGH_WORD(x,hx^sx);
 	q &= 0x7fffffff;
 	*quo = (sxy ? -q : q);
+	/*
+	 * If q is 0 and we need to return negative, we have to choose
+	 * the largest negative number (in 32 bits) because it is the
+	 * only value that is negative and congruent to 0 mod 2^31.
+	 */
+	if (q == 0 && sxy)
+	  *quo = 0x80000000;
 	return x;
 }

Reply via email to