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:
parent
c74abdace3
commit
c483a4dce8
2 changed files with 8 additions and 3 deletions
|
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue