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 })`
This commit is contained in:
parent
431ea5b67e
commit
442dc5fd91
2 changed files with 9 additions and 1 deletions
|
|
@ -112,7 +112,10 @@ impl FromStr for Nodes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ParsingState::ReadingNumber(start_index) => {
|
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(
|
nodes.push(Node::Number(
|
||||||
Float::parse(&filtered_string[start_index..i])
|
Float::parse(&filtered_string[start_index..i])
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,11 @@ use rug::Float;
|
||||||
|
|
||||||
use crate::nodes::{Function, Node, Nodes, Operator, PREC};
|
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]
|
#[test]
|
||||||
fn implicit_mult() {
|
fn implicit_mult() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue