Add support for the float_integer_part/1 and float_fractional_part/1 standard arithmetic functions
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user