mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
parse scientific notation
This commit is contained in:
parent
fb460ce984
commit
94fc5a1935
2 changed files with 26 additions and 0 deletions
|
@ -174,6 +174,16 @@ mod test_can {
|
|||
assert_can_float("-0.0", -0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scientific_positive() {
|
||||
assert_can_float("5e4", 5000.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scientific_negative() {
|
||||
assert_can_float("5e-4", 0.0005);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_max() {
|
||||
assert_can_num(&(i64::MAX.to_string()), i64::MAX);
|
||||
|
|
|
@ -118,6 +118,22 @@ fn chomp_number<'a>(mut bytes: &'a [u8]) -> (bool, usize) {
|
|||
is_float = true;
|
||||
bytes = &bytes[1..];
|
||||
}
|
||||
b'e' => {
|
||||
// maybe scientific notation?
|
||||
match bytes.get(1) {
|
||||
Some(b'-') => {
|
||||
is_float = true;
|
||||
bytes = &bytes[2..];
|
||||
}
|
||||
Some(c) if (*c as char).is_ascii_digit() => {
|
||||
is_float = true;
|
||||
bytes = &bytes[2..];
|
||||
}
|
||||
_ => {
|
||||
bytes = &bytes[1..];
|
||||
}
|
||||
}
|
||||
}
|
||||
b'_' => {
|
||||
// skip
|
||||
bytes = &bytes[1..];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue