Skip to content

Commit

Permalink
Full simplify before function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Feb 9, 2024
1 parent 6f176f8 commit 23d8a27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion numbat/src/bytecode_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl BytecodeInterpreter {
Expression::FunctionCall(_span, _full_span, name, args, _type) => {
// Put all arguments on top of the stack
for arg in args {
self.compile_expression(arg)?;
self.compile_expression_with_simplify(arg)?;
}

if let Some(idx) = self.vm.get_ffi_callable_idx(name) {
Expand Down
2 changes: 1 addition & 1 deletion numbat/src/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Quantity {
}

pub fn convert_to(&self, target_unit: &Unit) -> Result<Quantity> {
if &self.unit == target_unit || self.is_zero() {
if &self.unit == target_unit {
Ok(Quantity::new(self.value, target_unit.clone()))
} else {
// Remove common unit factors to reduce unnecessary conversion procedures
Expand Down
5 changes: 5 additions & 0 deletions numbat/tests/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,8 @@ fn test_overwrite_captured_constant() {
fn test_pretty_print_prefixes() {
expect_output("1 megabarn", "1 megabarn");
}

#[test]
fn test_full_simplify_for_function_calls() {
expect_output("floor(1.2 hours / hour)", "1");
}

0 comments on commit 23d8a27

Please sign in to comment.