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

Commit

Permalink
Use external float parser rather than rustc's
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ayazhafiz committed Jun 29, 2020
1 parent 1446f9c commit cd15175
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions libslide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ required-features = ["benchmark-internals"]

[dependencies]
rug = "1.9.0"
strtod = "0.0.1"

[dependencies.num-traits]
version = "0.2"
Expand Down
5 changes: 4 additions & 1 deletion libslide/src/scanner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod types;

use crate::diagnostics::Diagnostic;
use strtod::strtod;
use types::TokenType as TT;
pub use types::*;

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

self.output.push(tok!(TT::Float(float), (start, self.pos)));
}
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions slide/src/test/ui/giant_float.slide
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
===in
000000000.0055555555555555555555000005555555555555555555455555555555555555555555555555555555555555550000005555555555555555555555555555555455555555555555555555555555555555555555555555550000004
===in

~~~stdout
0.005555555555555556
~~~stdout

~~~stderr
~~~stderr

~~~exitcode
0
~~~exitcode

0 comments on commit cd15175

Please sign in to comment.