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!(