diff --git a/numbat/src/bytecode_interpreter.rs b/numbat/src/bytecode_interpreter.rs index a5d51271..7bbd7b05 100644 --- a/numbat/src/bytecode_interpreter.rs +++ b/numbat/src/bytecode_interpreter.rs @@ -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) { diff --git a/numbat/src/quantity.rs b/numbat/src/quantity.rs index d4bbf7db..9d298bf2 100644 --- a/numbat/src/quantity.rs +++ b/numbat/src/quantity.rs @@ -59,7 +59,7 @@ impl Quantity { } pub fn convert_to(&self, target_unit: &Unit) -> Result { - 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 diff --git a/numbat/tests/interpreter.rs b/numbat/tests/interpreter.rs index 4507e53f..a52103ce 100644 --- a/numbat/tests/interpreter.rs +++ b/numbat/tests/interpreter.rs @@ -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"); +}