Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit d8464c8

Browse files
committed
Use external float parser rather than rustc's
Per rust-lang/rust#31407, rustc's float parser may drop some valid float literals. For now use an external parser that does not have these problems. Closes #147
1 parent 1446f9c commit d8464c8

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

libslide/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ required-features = ["benchmark-internals"]
2626

2727
[dependencies]
2828
rug = "1.9.0"
29+
strtod = "0.0.1"
2930

3031
[dependencies.num-traits]
3132
version = "0.2"

libslide/src/scanner.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod types;
22

33
use crate::diagnostics::Diagnostic;
4+
use strtod::strtod;
45
use types::TokenType as TT;
56
pub use types::*;
67

@@ -123,7 +124,9 @@ impl Scanner {
123124
float_str.push(*self.next().unwrap());
124125
float_str.push_str(&self.collect_while(|c| c.is_digit(10)));
125126
}
126-
let float = float_str.parse::<f64>().unwrap();
127+
// TODO(https://github.com/rust-lang/rust/issues/31407): rustc's float parser may drop some
128+
// valid float literals. For now, use an external parser.
129+
let float = strtod(&float_str).unwrap();
127130

128131
self.output.push(tok!(TT::Float(float), (start, self.pos)));
129132
}

slide/src/test/ui/giant_float.slide

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
===in
2+
000000000.0055555555555555555555000005555555555555555555455555555555555555555555555555555555555555550000005555555555555555555555555555555455555555555555555555555555555555555555555555550000004
3+
===in
4+
5+
~~~stdout
6+
0.005555555555555556
7+
~~~stdout
8+
9+
~~~stderr
10+
~~~stderr
11+
12+
~~~exitcode
13+
0
14+
~~~exitcode

0 commit comments

Comments
 (0)