From 1ea397a80736184ee7f6fc83a3392fa1ddb16453 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 13 Oct 2023 14:33:36 -0600 Subject: [PATCH] correct (mod)/2 (#2103, #2107) --- src/machine/arithmetic_ops.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/machine/arithmetic_ops.rs b/src/machine/arithmetic_ops.rs index 149338b5..d1f764d6 100644 --- a/src/machine/arithmetic_ops.rs +++ b/src/machine/arithmetic_ops.rs @@ -1,5 +1,6 @@ -use dashu::base::Abs; -use dashu::base::Gcd; +use dashu::base::{Abs, Gcd, UnsignedAbs}; +use dashu::integer::IBig; +use dashu::integer::fast_div::ConstDivisor; use divrem::*; use num_order::NumOrd; @@ -854,7 +855,9 @@ pub(crate) fn modulus(x: Number, y: Number, arena: &mut Arena) -> Result &Integer::ZERO { ((n1 + Integer::ONE) / n2) - Integer::ONE } else { - n1 / n2 + let ring = ConstDivisor::new(n2.unsigned_abs()); + let n1 = n1.clone(); + IBig::from(ring.reduce(n1).residue()) } } -- 2.54.0