Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Jul 2023 21:44:04 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: df11fb9bf042 - main - divmoddi4: Handle negative remainders.
Message-ID:  <202307012144.361Li4DX001611@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=df11fb9bf0421ad11cfbc8834ca393a1a0c2748d

commit df11fb9bf0421ad11cfbc8834ca393a1a0c2748d
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-07-01 21:43:41 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-07-01 21:43:41 +0000

    divmoddi4: Handle negative remainders.
    
    The sign of the remainder matches the sign of the numerator in C.
    
    Reported by:    jrtc27
    Reviewed by:    jrtc27
    Differential Revision:  https://reviews.freebsd.org/D40832
---
 sys/libkern/divmoddi4.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sys/libkern/divmoddi4.c b/sys/libkern/divmoddi4.c
index e5bd81a90ad7..7c0a6a690f24 100644
--- a/sys/libkern/divmoddi4.c
+++ b/sys/libkern/divmoddi4.c
@@ -43,18 +43,18 @@ quad_t
 __divmoddi4(quad_t a, quad_t b, quad_t *rem)
 {
 	u_quad_t ua, ub, uq, urem;
-	int neg;
+	int negq, negr;
 
 	if (a < 0)
-		ua = -(u_quad_t)a, neg = 1;
+		ua = -(u_quad_t)a, negq = 1, negr = 1;
 	else
-		ua = a, neg = 0;
+		ua = a, negq = 0, negr = 0;
 	if (b < 0)
-		ub = -(u_quad_t)b, neg ^= 1;
+		ub = -(u_quad_t)b, negq ^= 1;
 	else
 		ub = b;
 	uq = __qdivrem(ua, ub, &urem);
 	if (rem != 0)
-		*rem = urem;
-	return (neg ? -uq : uq);
+		*rem = negr ? -urem : urem;
+	return (negq ? -uq : uq);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307012144.361Li4DX001611>