]> Repositorios git - scryer-prolog.git/commitdiff
correct (mod)/2 (#2103, #2107)
authorMark <[email protected]>
Fri, 13 Oct 2023 20:33:36 +0000 (14:33 -0600)
committerMark <[email protected]>
Fri, 13 Oct 2023 20:33:50 +0000 (14:33 -0600)
src/machine/arithmetic_ops.rs

index 149338b5593693ea4074b0637c454896695197a4..d1f764d6043caf1a331245e6c2ace9930f7f99b2 100644 (file)
@@ -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<Number,
         } else if n1 < &Integer::ZERO && n2 > &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())
         }
     }