]> Repositorios git - scryer-prolog.git/commitdiff
Add support for the float_integer_part/1 and float_fractional_part/1 standard arithme...
authorPaulo Moura <[email protected]>
Mon, 27 Sep 2021 11:27:09 +0000 (12:27 +0100)
committerPaulo Moura <[email protected]>
Sun, 24 Oct 2021 08:10:38 +0000 (09:10 +0100)
src/arithmetic.rs
src/instructions.rs
src/machine/machine_state_impl.rs
src/write.rs

index f5a3beeb2f956db86e540cd3438693d675b8b751..2edd90fdfb03e2dc2ef8f003c3747f34c9984d00 100644 (file)
@@ -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(
index 90cbeeab02ec4275a777e9c424376d840262b1f6..ba9909fd30a235cdc90f5e71144985605535a3b4 100644 (file)
@@ -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) => {
index c4929d2d5e1de17c2cb5585bc3be2b2ebe223658..60db86ddb9727d4c24bc20d9167500d382e7844b 100644 (file)
@@ -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));
 
index 1c1fc3dcfa95fc54b2027752fbf19a023d1bb3a3..1de2f53bd0a1be4338dc39ed15bc1f0744b51424 100644 (file)
@@ -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),
         }
     }
 }