aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-15 18:10:18 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-15 18:10:18 +0000
commit24abecee1c683edb5b23f0d21cb36fef2479933d (patch)
tree7714cdc6a70f4766ecb7eec31ed13251659ce9af
parent965a9835c35aabcd2fedb297bdc9a4b8e1220ed2 (diff)
parent1d65c58fa4b65048568f06960ee780ddeec3cf76 (diff)
downloadryu-build-tools-release.tar.gz
Snap for 11582845 from 1d65c58fa4b65048568f06960ee780ddeec3cf76 to build-tools-releasebuild-tools-release
Change-Id: I29f5b8f58a1cf277b9ba444501d401c4d16a2572
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.clippy.toml1
-rw-r--r--.github/workflows/ci.yml27
-rw-r--r--Android.bp35
-rw-r--r--Cargo.toml4
-rw-r--r--Cargo.toml.orig5
-rw-r--r--METADATA25
-rw-r--r--README.md2
-rw-r--r--src/buffer/mod.rs1
-rw-r--r--src/d2s_intrinsics.rs10
-rw-r--r--src/lib.rs3
-rw-r--r--tests/d2s_intrinsics_test.rs72
-rw-r--r--tests/d2s_test.rs3
-rw-r--r--tests/f2s_test.rs3
14 files changed, 152 insertions, 41 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 0fe1088..c76ffad 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "c275beb57ae09f9f503ed28ae6d9404f6e66c335"
+ "sha1": "668d654fd67c16bbeb53e5413c97e91a41bd84e5"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.clippy.toml b/.clippy.toml
deleted file mode 100644
index 0a54853..0000000
--- a/.clippy.toml
+++ /dev/null
@@ -1 +0,0 @@
-msrv = "1.36.0"
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index daf0ee2..cca8544 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -27,7 +27,7 @@ jobs:
rust: [nightly, beta, stable]
timeout-minutes: 45
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
@@ -46,11 +46,25 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.36.0
- run: cargo build
- run: cargo build --features small
+ doc:
+ name: Documentation
+ needs: pre_ci
+ if: needs.pre_ci.outputs.continue
+ runs-on: ubuntu-latest
+ timeout-minutes: 45
+ env:
+ RUSTDOCFLAGS: -Dwarnings
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dtolnay/rust-toolchain@nightly
+ - uses: dtolnay/install@cargo-docs-rs
+ - run: cargo docs-rs
+
miri:
name: Miri
needs: pre_ci
@@ -58,8 +72,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@miri
+ - run: cargo miri setup
- run: cargo miri test
env:
MIRIFLAGS: -Zmiri-strict-provenance
@@ -70,7 +85,7 @@ jobs:
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
- run: cargo clippy --tests --benches -- -Dclippy::all -Dclippy::pedantic
@@ -80,7 +95,7 @@ jobs:
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1
- run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1
@@ -92,7 +107,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-fuzz
- run: cargo fuzz check
diff --git a/Android.bp b/Android.bp
index f08db48..7af5f27 100644
--- a/Android.bp
+++ b/Android.bp
@@ -44,7 +44,7 @@ rust_library {
host_supported: true,
crate_name: "ryu",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["src/lib.rs"],
edition: "2018",
apex_available: [
@@ -60,7 +60,7 @@ rust_test {
host_supported: true,
crate_name: "common_test",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["tests/common_test.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -77,11 +77,32 @@ rust_test {
}
rust_test {
+ name: "ryu_test_tests_d2s_intrinsics_test",
+ host_supported: true,
+ crate_name: "d2s_intrinsics_test",
+ cargo_env_compat: true,
+ cargo_pkg_version: "1.0.16",
+ srcs: ["tests/d2s_intrinsics_test.rs"],
+ test_suites: ["general-tests"],
+ auto_gen_config: true,
+ test_options: {
+ unit_test: true,
+ },
+ edition: "2018",
+ rustlibs: [
+ "libnum_cpus",
+ "librand",
+ "librand_xorshift",
+ "libryu",
+ ],
+}
+
+rust_test {
name: "ryu_test_tests_d2s_table_test",
host_supported: true,
crate_name: "d2s_table_test",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["tests/d2s_table_test.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -102,7 +123,7 @@ rust_test {
host_supported: true,
crate_name: "d2s_test",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["tests/d2s_test.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -123,7 +144,7 @@ rust_test {
host_supported: true,
crate_name: "f2s_test",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["tests/f2s_test.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -144,7 +165,7 @@ rust_test {
host_supported: true,
crate_name: "s2d_test",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["tests/s2d_test.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -165,7 +186,7 @@ rust_test {
host_supported: true,
crate_name: "s2f_test",
cargo_env_compat: true,
- cargo_pkg_version: "1.0.13",
+ cargo_pkg_version: "1.0.16",
srcs: ["tests/s2f_test.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
diff --git a/Cargo.toml b/Cargo.toml
index 96a1627..a5c87c3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.36"
name = "ryu"
-version = "1.0.13"
+version = "1.0.16"
authors = ["David Tolnay <dtolnay@gmail.com>"]
exclude = [
"performance.png",
@@ -26,11 +26,13 @@ keywords = ["float"]
categories = [
"value-formatting",
"no-std",
+ "no-std::no-alloc",
]
license = "Apache-2.0 OR BSL-1.0"
repository = "https://github.com/dtolnay/ryu"
[package.metadata.docs.rs]
+rustdoc-args = ["--generate-link-to-definition"]
targets = ["x86_64-unknown-linux-gnu"]
[lib]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 60701a5..88db3cf 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,8 +1,8 @@
[package]
name = "ryu"
-version = "1.0.13" # don't forget to update html_root_url
+version = "1.0.16" # don't forget to update html_root_url
authors = ["David Tolnay <dtolnay@gmail.com>"]
-categories = ["value-formatting", "no-std"]
+categories = ["value-formatting", "no-std", "no-std::no-alloc"]
description = "Fast floating point to string conversion"
documentation = "https://docs.rs/ryu"
edition = "2018"
@@ -32,3 +32,4 @@ doc-scrape-examples = false
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
+rustdoc-args = ["--generate-link-to-definition"]
diff --git a/METADATA b/METADATA
index f957fb1..c83b028 100644
--- a/METADATA
+++ b/METADATA
@@ -1,23 +1,20 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update rust/crates/ryu
-# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+# Usage: tools/external_updater/updater.sh update external/rust/crates/ryu
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "ryu"
description: "Fast floating point to string conversion"
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/ryu"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/ryu/ryu-1.0.13.crate"
- }
- version: "1.0.13"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 4
- day: 3
+ year: 2024
+ month: 2
+ day: 7
+ }
+ homepage: "https://crates.io/crates/ryu"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/ryu/ryu-1.0.16.crate"
+ version: "1.0.16"
}
}
diff --git a/README.md b/README.md
index 0abd71f..998ea3e 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ C, [https://github.com/ulfjack/ryu][upstream].
uses nothing from the Rust standard library so is usable from no_std crates.*
[paper]: https://dl.acm.org/citation.cfm?id=3192369
-[upstream]: https://github.com/ulfjack/ryu/tree/abf76d252bc97300354857e64e80d4a2bf664291
+[upstream]: https://github.com/ulfjack/ryu/tree/77e767f5e056bab96e895072fc21618ecff2f44b
```toml
[dependencies]
diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs
index 2ccd9b0..905ee2f 100644
--- a/src/buffer/mod.rs
+++ b/src/buffer/mod.rs
@@ -83,6 +83,7 @@ impl Copy for Buffer {}
impl Clone for Buffer {
#[inline]
+ #[allow(clippy::non_canonical_clone_impl)] // false positive https://github.com/rust-lang/rust-clippy/issues/11072
fn clone(&self) -> Self {
Buffer::new()
}
diff --git a/src/d2s_intrinsics.rs b/src/d2s_intrinsics.rs
index f244a4d..a4e1fb1 100644
--- a/src/d2s_intrinsics.rs
+++ b/src/d2s_intrinsics.rs
@@ -36,16 +36,16 @@ pub fn div100(x: u64) -> u64 {
}
#[cfg_attr(feature = "no-panic", inline)]
-fn pow5_factor(mut value: u64) -> u32 {
+pub(crate) fn pow5_factor(mut value: u64) -> u32 {
+ const M_INV_5: u64 = 14757395258967641293; // 5 * m_inv_5 = 1 (mod 2^64)
+ const N_DIV_5: u64 = 3689348814741910323; // #{ n | n = 0 (mod 2^64) } = 2^64 / 5
let mut count = 0u32;
loop {
debug_assert!(value != 0);
- let q = div5(value);
- let r = (value as u32).wrapping_sub(5u32.wrapping_mul(q as u32));
- if r != 0 {
+ value = value.wrapping_mul(M_INV_5);
+ if value > N_DIV_5 {
break;
}
- value = q;
count += 1;
}
count
diff --git a/src/lib.rs b/src/lib.rs
index 0f4c89a..cf3a732 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -81,7 +81,7 @@
//! notation.
#![no_std]
-#![doc(html_root_url = "https://docs.rs/ryu/1.0.13")]
+#![doc(html_root_url = "https://docs.rs/ryu/1.0.16")]
#![allow(
clippy::cast_lossless,
clippy::cast_possible_truncation,
@@ -95,6 +95,7 @@
clippy::missing_panics_doc,
clippy::module_name_repetitions,
clippy::must_use_candidate,
+ clippy::needless_doctest_main,
clippy::similar_names,
clippy::too_many_lines,
clippy::unreadable_literal,
diff --git a/tests/d2s_intrinsics_test.rs b/tests/d2s_intrinsics_test.rs
new file mode 100644
index 0000000..0ac80c9
--- /dev/null
+++ b/tests/d2s_intrinsics_test.rs
@@ -0,0 +1,72 @@
+// Translated from C to Rust. The original C code can be found at
+// https://github.com/ulfjack/ryu and carries the following license:
+//
+// Copyright 2018 Ulf Adams
+//
+// The contents of this file may be used under the terms of the Apache License,
+// Version 2.0.
+//
+// (See accompanying file LICENSE-Apache or copy at
+// http://www.apache.org/licenses/LICENSE-2.0)
+//
+// Alternatively, the contents of this file may be used under the terms of
+// the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE-Boost or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+//
+// Unless required by applicable law or agreed to in writing, this software
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.
+
+#![allow(dead_code)]
+#![allow(
+ clippy::cast_lossless,
+ clippy::cast_possible_truncation,
+ clippy::unreadable_literal
+)]
+
+#[path = "../src/d2s_intrinsics.rs"]
+mod d2s_intrinsics;
+
+use d2s_intrinsics::pow5_factor;
+
+#[test]
+fn test_pow5_factor() {
+ assert_eq!(0, pow5_factor(1));
+ assert_eq!(0, pow5_factor(2));
+ assert_eq!(0, pow5_factor(3));
+ assert_eq!(0, pow5_factor(4));
+ assert_eq!(1, pow5_factor(5));
+ assert_eq!(0, pow5_factor(6));
+ assert_eq!(0, pow5_factor(7));
+ assert_eq!(0, pow5_factor(8));
+ assert_eq!(0, pow5_factor(9));
+ assert_eq!(1, pow5_factor(10));
+
+ assert_eq!(0, pow5_factor(12));
+ assert_eq!(0, pow5_factor(14));
+ assert_eq!(0, pow5_factor(16));
+ assert_eq!(0, pow5_factor(18));
+ assert_eq!(1, pow5_factor(20));
+
+ assert_eq!(2, pow5_factor(5 * 5));
+ assert_eq!(3, pow5_factor(5 * 5 * 5));
+ assert_eq!(4, pow5_factor(5 * 5 * 5 * 5));
+ assert_eq!(5, pow5_factor(5 * 5 * 5 * 5 * 5));
+ assert_eq!(6, pow5_factor(5 * 5 * 5 * 5 * 5 * 5));
+ assert_eq!(7, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5));
+ assert_eq!(8, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
+ assert_eq!(9, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
+ assert_eq!(10, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
+
+ assert_eq!(0, pow5_factor(42));
+ assert_eq!(1, pow5_factor(42 * 5));
+ assert_eq!(2, pow5_factor(42 * 5 * 5));
+ assert_eq!(3, pow5_factor(42 * 5 * 5 * 5));
+ assert_eq!(4, pow5_factor(42 * 5 * 5 * 5 * 5));
+ assert_eq!(5, pow5_factor(42 * 5 * 5 * 5 * 5 * 5));
+
+ assert_eq!(27, pow5_factor(7450580596923828125)); // 5^27, largest power of 5 < 2^64.
+ assert_eq!(1, pow5_factor(18446744073709551615)); // 2^64 - 1, largest multiple of 5 < 2^64.
+ assert_eq!(0, pow5_factor(18446744073709551614)); // 2^64 - 2, largest non-multiple of 5 < 2^64.
+}
diff --git a/tests/d2s_test.rs b/tests/d2s_test.rs
index 368cab6..7e8eba6 100644
--- a/tests/d2s_test.rs
+++ b/tests/d2s_test.rs
@@ -82,7 +82,8 @@ fn test_basic() {
check!(-0.0);
check!(1.0);
check!(-1.0);
- assert_eq!(pretty(f64::NAN), "NaN");
+ assert_eq!(pretty(f64::NAN.copysign(1.0)), "NaN");
+ assert_eq!(pretty(f64::NAN.copysign(-1.0)), "NaN");
assert_eq!(pretty(f64::INFINITY), "inf");
assert_eq!(pretty(f64::NEG_INFINITY), "-inf");
}
diff --git a/tests/f2s_test.rs b/tests/f2s_test.rs
index 927fa7e..d6249a3 100644
--- a/tests/f2s_test.rs
+++ b/tests/f2s_test.rs
@@ -75,7 +75,8 @@ fn test_basic() {
check!(-0.0);
check!(1.0);
check!(-1.0);
- assert_eq!(pretty(f32::NAN), "NaN");
+ assert_eq!(pretty(f32::NAN.copysign(1.0)), "NaN");
+ assert_eq!(pretty(f32::NAN.copysign(-1.0)), "NaN");
assert_eq!(pretty(f32::INFINITY), "inf");
assert_eq!(pretty(f32::NEG_INFINITY), "-inf");
}