fix: missing implicit operator

(0.2)20^2 was missing a mult and caused a crash,
even though (0.2)20 was just fine.
This commit is contained in:
electria 2026-10-24 16:15:13 -07:00
commit c483a4dce8
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 8 additions and 3 deletions

View file

@ -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()));
}

View file

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