From: Paulo Moura Date: Mon, 27 Sep 2021 11:27:09 +0000 (+0100) Subject: Add support for the float_integer_part/1 and float_fractional_part/1 standard arithme... X-Git-Tag: v0.9.2~29^2^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=495025dafbae5fe27e8fcbda53a2ab6a3df288ad;p=scryer-prolog.git Add support for the float_integer_part/1 and float_fractional_part/1 standard arithmetic functions --- diff --git a/src/arithmetic.rs b/src/arithmetic.rs index f5a3beeb..2edd90fd 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -165,6 +165,8 @@ impl<'a> ArithmeticEvaluator<'a> { "round" => Ok(ArithmeticInstruction::Round(a1, t)), "ceiling" => Ok(ArithmeticInstruction::Ceiling(a1, t)), "floor" => Ok(ArithmeticInstruction::Floor(a1, t)), + "float_integer_part" => Ok(ArithmeticInstruction::FloatIntegerPart(a1, t)), + "float_fractional_part" => Ok(ArithmeticInstruction::FloatFractionalPart(a1, t)), "sign" => Ok(ArithmeticInstruction::Sign(a1, t)), "\\" => Ok(ArithmeticInstruction::BitwiseComplement(a1, t)), _ => Err(ArithmeticError::NonEvaluableFunctor( diff --git a/src/instructions.rs b/src/instructions.rs index 90cbeeab..ba9909fd 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -373,6 +373,8 @@ pub(crate) enum ArithmeticInstruction { Round(ArithmeticTerm, usize), Ceiling(ArithmeticTerm, usize), Floor(ArithmeticTerm, usize), + FloatIntegerPart(ArithmeticTerm, usize), + FloatFractionalPart(ArithmeticTerm, usize), Neg(ArithmeticTerm, usize), Plus(ArithmeticTerm, usize), BitwiseComplement(ArithmeticTerm, usize), @@ -495,6 +497,8 @@ impl ArithmeticInstruction { &ArithmeticInstruction::Floor(ref at, t) => { arith_instr_unary_functor(h, "floor", at, t) } + &ArithmeticInstruction::FloatIntegerPart(ref at, t) => arith_instr_unary_functor(h, "trunc", at, t), + &ArithmeticInstruction::FloatFractionalPart(ref at, t) => arith_instr_unary_functor(h, "fract", at, t), &ArithmeticInstruction::Neg(ref at, t) => arith_instr_unary_functor(h, "-", at, t), &ArithmeticInstruction::Plus(ref at, t) => arith_instr_unary_functor(h, "+", at, t), &ArithmeticInstruction::BitwiseComplement(ref at, t) => { diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index c4929d2d..60db86dd 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -1175,6 +1175,18 @@ impl MachineState { self.interms[t - 1] = self.floor(n1); self.p += 1; } + &ArithmeticInstruction::FloatIntegerPart(ref a1, t) => { + let n1 = try_or_fail!(self, self.get_number(a1)); + + self.interms[t - 1] = self.trunc(n1); + self.p += 1; + } + &ArithmeticInstruction::FloatFractionalPart(ref a1, t) => { + let n1 = try_or_fail!(self, self.get_number(a1)); + + self.interms[t - 1] = self.fract(n1); + self.p += 1; + } &ArithmeticInstruction::Plus(ref a1, t) => { let n1 = try_or_fail!(self, self.get_number(a1)); diff --git a/src/write.rs b/src/write.rs index 1c1fc3dc..1de2f53b 100644 --- a/src/write.rs +++ b/src/write.rs @@ -649,6 +649,8 @@ impl fmt::Display for ArithmeticInstruction { &ArithmeticInstruction::Ceiling(ref a, ref t) => write!(f, "ceiling {}, @{}", a, t), &ArithmeticInstruction::Floor(ref a, ref t) => write!(f, "floor {}, @{}", a, t), &ArithmeticInstruction::Float(ref a, ref t) => write!(f, "float {}, @{}", a, t), + &ArithmeticInstruction::FloatIntegerPart(ref a, ref t) => write!(f, "float_integer_part {}, @{}", a, t), + &ArithmeticInstruction::FloatFractionalPart(ref a, ref t) => write!(f, "float_fractional_part {}, @{}", a, t), } } }