Skip to content

Commit 36b5ab8

Browse files
authored
Merge pull request #1 from Alexhuszagh/fork
Migrate to a v2 fork.
2 parents 83a49b8 + dd9ebc2 commit 36b5ab8

File tree

15 files changed

+66
-44
lines changed

15 files changed

+66
-44
lines changed

.github/workflows/ci.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
rust: [1.37.0, stable, nightly]
14+
rust: [1.56.0, stable, nightly]
1515
steps:
1616
- uses: actions/checkout@v2
1717
with:
@@ -23,6 +23,23 @@ jobs:
2323
- run: cargo test
2424
- run: cd extras/data-tests && cargo run --release
2525

26+
msrv:
27+
name: Rust ${{matrix.rust}}
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
rust: [1.37.0]
33+
steps:
34+
- uses: actions/checkout@v2
35+
with:
36+
submodules: recursive
37+
- uses: dtolnay/rust-toolchain@master
38+
with:
39+
toolchain: ${{matrix.rust}}
40+
- run: cargo check
41+
- run: cargo build
42+
2643
cross:
2744
name: Rust ${{matrix.target}}
2845
runs-on: ubuntu-latest

Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
2-
name = "fast-float"
3-
version = "0.2.0"
4-
authors = ["Ivan Smirnov <[email protected]>"]
5-
repository = "https://github.com/aldanor/fast-float-rust"
6-
documentation = "https://docs.rs/fast-float"
2+
name = "fast-float2"
3+
version = "0.2.1"
4+
authors = ["Ivan Smirnov <[email protected]>", "Alex Huszagh <[email protected]>"]
5+
repository = "https://github.com/Alexhuszagh/fast-float-rust"
6+
documentation = "https://docs.rs/fast-float2"
77
description = "Fast floating-point number parser."
88
keywords = ["parser", "parsing", "parse", "float", "no-std"]
99
categories = ["parser-implementations", "parsing", "text-processing", "algorithms", "no-std"]
@@ -12,6 +12,8 @@ license = "MIT OR Apache-2.0"
1212
autobenches = false
1313
edition = "2018"
1414
exclude = ["benches/*", "extras/*"]
15+
# FIXME: rust-version is not supported until 1.56.0.
16+
rust-version = "1.37"
1517

1618
[features]
1719
default = ["std"]

README.md

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
fast-float
2-
==========
1+
fast-float2
2+
===========
33

4-
[![Build](https://github.com/aldanor/fast-float-rust/workflows/CI/badge.svg)](https://github.com/aldanor/fast-float-rust/actions?query=branch%3Amaster)
5-
[![Latest Version](https://img.shields.io/crates/v/fast-float.svg)](https://crates.io/crates/fast-float)
6-
[![Documentation](https://docs.rs/fast-float/badge.svg)](https://docs.rs/fast-float)
4+
[![Build](https://github.com/Alexhuszagh/fast-float-rust/workflows/CI/badge.svg)](https://github.com/Alexhuszagh/fast-float-rust/actions?query=branch%3Amaster)
5+
[![Latest Version](https://img.shields.io/crates/v/fast-float2.svg)](https://crates.io/crates/fast-float2)
6+
[![Documentation](https://docs.rs/fast-float2/badge.svg)](https://docs.rs/fast-float2)
77
[![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
88
[![MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
99
[![Rustc 1.37+](https://img.shields.io/badge/rustc-1.37+-lightgray.svg)](https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html)
@@ -12,7 +12,7 @@ This crate provides a super-fast decimal number parser from strings into floats.
1212

1313
```toml
1414
[dependencies]
15-
fast-float = "0.2"
15+
fast-float2 = "0.2.1"
1616
```
1717

1818
There are no dependencies and the crate can be used in a no_std context by disabling the "std" feature.
@@ -21,10 +21,10 @@ There are no dependencies and the crate can be used in a no_std context by disab
2121

2222
## Usage
2323

24-
There's two top-level functions provided:
25-
[`parse()`](https://docs.rs/fast-float/latest/fast_float/fn.parse.html) and
24+
There's two top-level functions provided:
25+
[`parse()`](https://docs.rs/fast-float/latest/fast_float/fn.parse.html) and
2626
[`parse_partial()`](https://docs.rs/fast-float/latest/fast_float/fn.parse_partial.html), both taking
27-
either a string or a bytes slice and parsing the input into either `f32` or `f64`:
27+
either a string or a bytes slice and parsing the input into either `f32` or `f64`:
2828

2929
- `parse()` treats the whole string as a decimal number and returns an error if there are
3030
invalid characters or if the string is empty.
@@ -39,12 +39,12 @@ Example:
3939
```rust
4040
// Parse the entire string as a decimal number.
4141
let s = "1.23e-02";
42-
let x: f32 = fast_float::parse(s).unwrap();
42+
let x: f32 = fast_float2::parse(s).unwrap();
4343
assert_eq!(x, 0.0123);
4444

4545
// Parse as many characters as possible as a decimal number.
4646
let s = "1.23e-02foo";
47-
let (x, n) = fast_float::parse_partial::<f32, _>(s).unwrap();
47+
let (x, n) = fast_float2::parse_partial::<f32, _>(s).unwrap();
4848
assert_eq!(x, 0.0123);
4949
assert_eq!(n, 8);
5050
assert_eq!(&s[n..], "foo");
@@ -53,19 +53,22 @@ assert_eq!(&s[n..], "foo");
5353
## Details
5454

5555
This crate is a direct port of Daniel Lemire's [`fast_float`](https://github.com/fastfloat/fast_float)
56-
C++ library (valuable discussions with Daniel while porting it helped shape the crate and get it to
56+
C++ library (valuable discussions with Daniel while porting it helped shape the crate and get it to
5757
the performance level it's at now), with some Rust-specific tweaks. Please see the original
5858
repository for many useful details regarding the algorithm and the implementation.
5959

60-
The parser is locale-independent. The resulting value is the closest floating-point values (using either
61-
`f32` or `f64`), using the "round to even" convention for values that would otherwise fall right in-between
62-
two values. That is, we provide exact parsing according to the IEEE standard.
60+
The parser is locale-independent. The resulting value is the closest floating-point values (using either
61+
`f32` or `f64`), using the "round to even" convention for values that would otherwise fall right in-between
62+
two values. That is, we provide exact parsing according to the IEEE standard.
6363

6464
Infinity and NaN values can be parsed, along with scientific notation.
6565

6666
Both little-endian and big-endian platforms are equally supported, with extra optimizations enabled
6767
on little-endian architectures.
6868

69+
Since [fast-float-rust](https://github.com/aldanor/fast-float-rust) is unmaintained, this is a fork
70+
containing the patches and security updates.
71+
6972
## Testing
7073

7174
There are a few ways this crate is tested:
@@ -80,7 +83,7 @@ There are a few ways this crate is tested:
8083
## Performance
8184

8285
The presented parser seems to beat all of the existing C/C++/Rust float parsers known to us at the
83-
moment by a large margin, in all of the datasets we tested it on so far – see detailed benchmarks
86+
moment by a large margin, in all of the datasets we tested it on so far – see detailed benchmarks
8487
below (the only exception being the original fast_float C++ library, of course – performance of
8588
which is within noise bounds of this crate). On modern machines like Apple M1, parsing throughput
8689
can reach up to 1.5 GB/s.
@@ -103,7 +106,7 @@ C++ library, here are few brief notes:
103106

104107
## Benchmarks
105108

106-
Below are tables of best timings in nanoseconds for parsing a single number
109+
Below are tables of best timings in nanoseconds for parsing a single number
107110
into a 64-bit float.
108111

109112
#### Intel i7-4771
@@ -169,12 +172,12 @@ AMD Rome, Linux, Rust 1.49.
169172

170173
#### Notes
171174

172-
- The two test files referred above can be found in
175+
- The two test files referred above can be found in
173176
[this](https://github.com/lemire/simple_fastfloat_benchmark) repository.
174177
- The Rust part of the table (along with a few other benchmarks) can be generated via
175178
the benchmark tool that can be found under `extras/simple-bench` of this repo.
176179
- The C/C++ part of the table (along with a few other benchmarks and parsers) can be
177-
generated via a C++ utility that can be found in
180+
generated via a C++ utility that can be found in
178181
[this](https://github.com/lemire/simple_fastfloat_benchmark) repository.
179182

180183
<br>

extras/data-tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0"
88
publish = false
99

1010
[dependencies]
11-
fast-float = { path = "../.." }
11+
fast-float2 = { path = "../.." }

extras/data-tests/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl TestCase {
2222
}
2323
}
2424

25-
fn execute_one<F: fast_float::FastFloat>(&self, expected: F) {
25+
fn execute_one<F: fast_float2::FastFloat>(&self, expected: F) {
2626
let r = F::parse_float_partial(&self.string);
2727
if !r.is_ok() {
2828
dbg!(self);

extras/simple-bench/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
88
publish = false
99

1010
[dependencies]
11-
fast-float = { path = "../.." }
11+
fast-float2 = { path = "../.." }
1212
structopt = "0.3"
1313
anyhow = "1.0"
1414
lexical = "5.2"

extras/simple-bench/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This crate provides a utility for benchmarking the `fast-float` crate against
1+
This crate provides a utility for benchmarking the `fast-float2` crate against
22
`lexical_core` and standard library's `FromStr`.
33

44
To run a file-based test:
@@ -18,8 +18,8 @@ To run a randomized test:
1818
cargo run --release -- random uniform
1919
```
2020

21-
For more details and options (choosing a different random generator, storing
22-
randomized inputs to a file, changing the number of runs, or switching between
21+
For more details and options (choosing a different random generator, storing
22+
randomized inputs to a file, changing the number of runs, or switching between
2323
32-bit and 64-bit floats), refer to help:
2424

2525
```

extras/simple-bench/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use fastrand::Rng;
1010
use lexical::FromLexical;
1111
use structopt::StructOpt;
1212

13-
use fast_float::FastFloat;
13+
use fast_float2::FastFloat;
1414

1515
use random::RandomGen;
1616

@@ -138,7 +138,7 @@ impl Method {
138138
let data = &input.data;
139139
let times = match self {
140140
Self::FastFloat => run_bench(data, repeat, |s: &str| {
141-
fast_float::parse_partial::<T, _>(s).unwrap_or_default().0
141+
fast_float2::parse_partial::<T, _>(s).unwrap_or_default().0
142142
}),
143143
Self::Lexical => run_bench(data, repeat, |s: &str| {
144144
lexical_core::parse_partial::<T>(s.as_bytes())

fuzz/fuzz_targets/fast_float.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn black_box<T>(dummy: T) -> T {
1111
}
1212

1313
fuzz_target!(|data: &[u8]| {
14-
let _ = black_box(::fast_float::parse::<f32, _>(data));
15-
let _ = black_box(::fast_float::parse::<f64, _>(data));
14+
let _ = black_box(::fast_float2::parse::<f32, _>(data));
15+
let _ = black_box(::fast_float2::parse::<f64, _>(data));
1616
});

fuzz/fuzz_targets/roundtrip_f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use libfuzzer_sys::fuzz_target;
55
// is small enough that we can test it exhaustively
66

77
fn check_roundtrip(float: f64, string: impl AsRef<str>) {
8-
let result = ::fast_float::parse::<f64, _>(string.as_ref()).unwrap();
8+
let result = ::fast_float2::parse::<f64, _>(string.as_ref()).unwrap();
99
if float.is_nan() {
1010
assert!(result.is_nan());
1111
} else {

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
//! ```rust
2121
//! // Parse the entire string as a decimal number.
2222
//! let s = "1.23e-02";
23-
//! let x: f32 = fast_float::parse(s).unwrap();
23+
//! let x: f32 = fast_float2::parse(s).unwrap();
2424
//! assert_eq!(x, 0.0123);
2525
//!
2626
//! // Parse as many characters as possible as a decimal number.
2727
//! let s = "1.23e-02foo";
28-
//! let (x, n) = fast_float::parse_partial::<f32, _>(s).unwrap();
28+
//! let (x, n) = fast_float2::parse_partial::<f32, _>(s).unwrap();
2929
//! assert_eq!(x, 0.0123);
3030
//! assert_eq!(n, 8);
3131
//! assert_eq!(&s[n..], "foo");

tests/test_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use fast_float::{parse, parse_partial, FastFloat};
1+
use fast_float2::{parse, parse_partial, FastFloat};
22

33
macro_rules! check_ok {
44
($s:expr, $x:expr) => {

tests/test_basic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ macro_rules! check {
2424
let string = String::from($s);
2525
let s = string.as_bytes();
2626
let expected: $ty = $e;
27-
let result = fast_float::parse::<$ty, _>(s).unwrap();
27+
let result = fast_float2::parse::<$ty, _>(s).unwrap();
2828
assert_eq!(result, expected);
2929
let lex = lexical_core::parse::<$ty>(s).unwrap();
3030
assert_eq!(result, lex);
@@ -411,7 +411,7 @@ fn test_f64_pow10() {
411411
for i in -308..=308 {
412412
let s = format!("1e{}", i);
413413
let v = f64::from_str(&s).unwrap();
414-
assert_eq!(fast_float::parse::<f64, _>(s).unwrap(), v);
414+
assert_eq!(fast_float2::parse::<f64, _>(s).unwrap(), v);
415415
}
416416
}
417417

@@ -420,6 +420,6 @@ fn test_f32_pow10() {
420420
for i in -38..=38 {
421421
let s = format!("1e{}", i);
422422
let v = f32::from_str(&s).unwrap();
423-
assert_eq!(fast_float::parse::<f32, _>(s).unwrap(), v);
423+
assert_eq!(fast_float2::parse::<f32, _>(s).unwrap(), v);
424424
}
425425
}

tests/test_exhaustive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn test_f32_exhaustive_ryu() {
55
for i in 0..0xFFFF_FFFF_u32 {
66
let a: f32 = unsafe { core::mem::transmute(i) };
77
let s = buf.format(a);
8-
let b: f32 = fast_float::parse(s).unwrap();
8+
let b: f32 = fast_float2::parse(s).unwrap();
99
assert!(a == b || (a.is_nan() && b.is_nan()));
1010
}
1111
}

tests/test_random.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn test_f64_random_from_u64() {
99
let i: u64 = rng.u64(0..0xFFFF_FFFF_FFFF_FFFF);
1010
let a: f64 = unsafe { core::mem::transmute(i) };
1111
let s = buf.format(a);
12-
let b: f64 = fast_float::parse(s).unwrap();
12+
let b: f64 = fast_float2::parse(s).unwrap();
1313
assert!(a == b || (a.is_nan() && b.is_nan()));
1414
}
1515
}

0 commit comments

Comments
 (0)