From: Mark Thom Date: Fri, 15 May 2020 04:25:39 +0000 (-0600) Subject: implement (div)/2 properly (#435) X-Git-Tag: v0.8.123~34 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=8754157810b3501b0215bcf059fe10b17b6affd3;p=scryer-prolog.git implement (div)/2 properly (#435) --- diff --git a/src/prolog/machine/arithmetic_ops.rs b/src/prolog/machine/arithmetic_ops.rs index 21074889..32cad18a 100644 --- a/src/prolog/machine/arithmetic_ops.rs +++ b/src/prolog/machine/arithmetic_ops.rs @@ -268,20 +268,10 @@ impl MachineState { pub(crate) fn int_floor_div(&self, n1: Number, n2: Number) -> Result { - match n1 / n2 { - Ok(result) => { - Ok(rnd_i(&result).to_owned()) - } - Err(e) => { - let stub = MachineError::functor_stub(clause_name!("(div)"), 2); - Err(self.error_form( - MachineError::evaluation_error( - e - ), - stub - )) - } - } + let stub = MachineError::functor_stub(clause_name!("(div)"), 2); + let modulus = self.modulus(n1.clone(), n2.clone())?; + + self.idiv(try_numeric_result!(self, n1 - modulus, stub)?, n2) } pub(crate)