From 442dc5fd913c44396822ea0841c542dbfdd8d6da Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 24 Jul 2026 11:24:22 -0700 Subject: [PATCH] fix: 1e-1 edge case the "wrap up any unfinished parsing" section doesn't need to be changed, since this edge case is only valid when there is a number after the '-' which there never is in the case of only one extra character in other words, 1e- is not valid: `NumberParsing("1e-", ParseFloatError { kind: ExpNoDigits })` --- src/nodes/from_str.rs | 5 ++++- src/nodes/tests.rs | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index f07f99f..5db581e 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -112,7 +112,10 @@ impl FromStr for Nodes { } } ParsingState::ReadingNumber(start_index) => { - if !is_number_char(c) { + if !is_number_char(c) + // don't stop reading number on a special case, eg "1e-1" + && !(filtered_string.chars().nth(i - 1) == Some('e') && c == '-') + { nodes.push(Node::Number( Float::parse(&filtered_string[start_index..i]) .map_err(|e| { diff --git a/src/nodes/tests.rs b/src/nodes/tests.rs index 405efe5..2acaac0 100644 --- a/src/nodes/tests.rs +++ b/src/nodes/tests.rs @@ -5,6 +5,11 @@ use rug::Float; use crate::nodes::{Function, Node, Nodes, Operator, PREC}; +#[test] +fn e_edge_case() { + assert_eq!(Nodes::from_str("1e-1").unwrap().evaluate().to_f64(), 0.1) +} + #[test] fn implicit_mult() { assert_eq!(