From c483a4dce8c6b7e17a70e420bf5d2ce233eb334f Mon Sep 17 00:00:00 2001 From: electria Date: Sat, 24 Oct 2026 16:15:13 -0700 Subject: [PATCH] fix: missing implicit operator (0.2)20^2 was missing a mult and caused a crash, even though (0.2)20 was just fine. --- src/nodes/parse.rs | 4 +--- src/nodes/tests.rs | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/nodes/parse.rs b/src/nodes/parse.rs index e3da6e6..6da0edb 100644 --- a/src/nodes/parse.rs +++ b/src/nodes/parse.rs @@ -129,9 +129,7 @@ impl FromStr for Nodes { && !(c == 'e' && filtered_string.chars().nth(i + 1).is_some_and(|c| c == '-')) && !(c == '-' && filtered_string.chars().nth(i - 1).is_some_and(|c| c == 'e')) { - // likely a constant before this number - // no need to check for parenthesis here though (why?) - if matches!(nodes.last(), Some(Node::Number(_))) { + if matches!(nodes.last(), Some(Node::ParenthesisEnd | Node::Number(_))) { nodes.push(Node::Operator(Default::default())); } diff --git a/src/nodes/tests.rs b/src/nodes/tests.rs index 2f22d8a..a4de7d2 100644 --- a/src/nodes/tests.rs +++ b/src/nodes/tests.rs @@ -56,3 +56,10 @@ fn constant_implicit_mult() { fn pi_precision() { assert_eq!(eval("sin(pi)"), 0.) } + +#[test] +fn operator_after_parenthesis() { + assert_eq!(eval("(0.2)20"), 4.); + assert_eq!(eval("(0.2)20^2"), 80.); + assert_eq!(eval("(0.2)20^2/2 - (0.2)10^2/2"), 30.); +}