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.); +}