-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional, external tests for floating point parsing.
Running these tests takes hours, so they are not run by @bors.
- Loading branch information
Robin Kruppe
committed
Aug 9, 2015
1 parent
ba792a4
commit 82dbc2e
Showing
11 changed files
with
664 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::io; | ||
use std::io::prelude::*; | ||
use std::mem::transmute; | ||
|
||
// Nothing up my sleeve: Just (PI - 3) in base 16. | ||
#[allow(dead_code)] | ||
pub const SEED: [u32; 3] = [0x243f_6a88, 0x85a3_08d3, 0x1319_8a2e]; | ||
|
||
pub fn validate(text: String) { | ||
let mut out = io::stdout(); | ||
let x: f64 = text.parse().unwrap(); | ||
let f64_bytes: u64 = unsafe { transmute(x) }; | ||
let x: f32 = text.parse().unwrap(); | ||
let f32_bytes: u32 = unsafe { transmute(x) }; | ||
writeln!(&mut out, "{:016x} {:08x} {}", f64_bytes, f32_bytes, text).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
mod _common; | ||
|
||
use _common::validate; | ||
|
||
fn main() { | ||
let mut pow = vec![]; | ||
for i in 0..63 { | ||
pow.push(1u64 << i); | ||
} | ||
for a in &pow { | ||
for b in &pow { | ||
for c in &pow { | ||
validate((a | b | c).to_string()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
mod _common; | ||
|
||
use _common::validate; | ||
|
||
fn main() { | ||
for e in 300..310 { | ||
for i in 0..100000 { | ||
validate(format!("{}e{}", i, e)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(rand)] | ||
|
||
extern crate rand; | ||
|
||
mod _common; | ||
|
||
use std::char; | ||
use rand::{IsaacRng, Rng, SeedableRng}; | ||
use rand::distributions::{Range, Sample}; | ||
use _common::{validate, SEED}; | ||
|
||
fn main() { | ||
let mut rnd = IsaacRng::from_seed(&SEED); | ||
let mut range = Range::new(0, 10); | ||
for _ in 0..5_000_000u64 { | ||
let num_digits = rnd.gen_range(100, 300); | ||
let digits = gen_digits(num_digits, &mut range, &mut rnd); | ||
validate(digits); | ||
} | ||
} | ||
|
||
fn gen_digits<R: Rng>(n: u32, range: &mut Range<u32>, rnd: &mut R) -> String { | ||
let mut s = String::new(); | ||
for _ in 0..n { | ||
let digit = char::from_digit(range.sample(rnd), 10).unwrap(); | ||
s.push(digit); | ||
} | ||
s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(rand)] | ||
|
||
extern crate rand; | ||
|
||
mod _common; | ||
|
||
use _common::{validate, SEED}; | ||
use rand::{IsaacRng, Rng, SeedableRng}; | ||
use std::mem::transmute; | ||
|
||
fn main() { | ||
let mut rnd = IsaacRng::from_seed(&SEED); | ||
let mut i = 0; | ||
while i < 10_000_000 { | ||
let bits = rnd.next_u64(); | ||
let x: f64 = unsafe { transmute(bits) }; | ||
if x.is_finite() { | ||
validate(format!("{:e}", x)); | ||
i += 1; | ||
} | ||
} | ||
} |
Oops, something went wrong.