Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full simplify arguments in function calls #326

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
Loading