Skip to content

Commit 23d8a27

Browse files
committed
Full simplify before function calls
1 parent 6f176f8 commit 23d8a27

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

numbat/src/bytecode_interpreter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl BytecodeInterpreter {
142142
Expression::FunctionCall(_span, _full_span, name, args, _type) => {
143143
// Put all arguments on top of the stack
144144
for arg in args {
145-
self.compile_expression(arg)?;
145+
self.compile_expression_with_simplify(arg)?;
146146
}
147147

148148
if let Some(idx) = self.vm.get_ffi_callable_idx(name) {

numbat/src/quantity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Quantity {
5959
}
6060

6161
pub fn convert_to(&self, target_unit: &Unit) -> Result<Quantity> {
62-
if &self.unit == target_unit || self.is_zero() {
62+
if &self.unit == target_unit {
6363
Ok(Quantity::new(self.value, target_unit.clone()))
6464
} else {
6565
// Remove common unit factors to reduce unnecessary conversion procedures

numbat/tests/interpreter.rs

+5
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,8 @@ fn test_overwrite_captured_constant() {
595595
fn test_pretty_print_prefixes() {
596596
expect_output("1 megabarn", "1 megabarn");
597597
}
598+
599+
#[test]
600+
fn test_full_simplify_for_function_calls() {
601+
expect_output("floor(1.2 hours / hour)", "1");
602+
}

0 commit comments

Comments
 (0)