<NME> lib.rs
<BEF> mod common;
mod d2s;
mod d2s_full_table;
//! available under the creative commons CC-BY-SA license.
//!
//! This Rust implementation is a line-by-line port of Ulf Adams' implementation
//! in C, [https://github.com/ulfjack/ryu][upstream].
//!
//! [paper]: https://dl.acm.org/citation.cfm?id=3192369
//! [upstream]: https://github.com/ulfjack/ryu
//!
//! # Example
//!
//! ```
//! fn main() {
//!     let mut buffer = ryu::Buffer::new();
//!     let printed = buffer.format(1.234);
//!     assert_eq!(printed, "1.234");
//! }
//! ```
//!
//! ## Performance (lower is better)
//!
//! ![performance](https://raw.githubusercontent.com/dtolnay/ryu/master/performance.png)
//!
//! You can run upstream's benchmarks with:
//!
//! ```console
//! $ git clone https://github.com/ulfjack/ryu c-ryu
//! $ cd c-ryu
//! $ bazel run -c opt //ryu/benchmark
//! ```
//!
//! And the same benchmark against our implementation with:
//!
//! ```console
//! $ git clone https://github.com/dtolnay/ryu rust-ryu
//! $ cd rust-ryu
//! $ cargo run --example upstream_benchmark --release
//! ```
//!
//! These benchmarks measure the average time to print a 32-bit float and average
//! time to print a 64-bit float, where the inputs are distributed as uniform random
//! bit patterns 32 and 64 bits wide.
//!
//! The upstream C code, the unsafe direct Rust port, and the safe pretty Rust API
//! all perform the same, taking around 21 nanoseconds to format a 32-bit float and
//! 31 nanoseconds to format a 64-bit float.
//!
//! There is also a Rust-specific benchmark comparing this implementation to the
//! standard library which you can run with:
//!
//! ```console
//! $ cargo bench
//! ```
//!
//! The benchmark shows Ryū approximately 2-5x faster than the standard library
//! across a range of f32 and f64 inputs. Measurements are in nanoseconds per
//! iteration; smaller is better.
//!
//! ## Formatting
//!
//! This library tends to produce more human-readable output than the standard
//! library's to\_string, which never uses scientific notation. Here are two
//! examples:
//!
//! - *ryu:* 1.23e40, *std:* 12300000000000000000000000000000000000000
//! - *ryu:* 1.23e-40, *std:* 0.000000000000000000000000000000000000000123
//!
//! Both libraries print short decimals such as 0.0000123 without scientific
//! notation.

#![no_std]
#![doc(html_root_url = "https://docs.rs/ryu/1.0.11")]
#![allow(
    clippy::cast_lossless,
    clippy::cast_possible_truncation,
    clippy::cast_possible_wrap,
    clippy::cast_sign_loss,
    clippy::checked_conversions,
    clippy::doc_markdown,
    clippy::expl_impl_clone_on_copy,
    clippy::if_not_else,
    clippy::many_single_char_names,
    clippy::missing_panics_doc,
    clippy::module_name_repetitions,
    clippy::must_use_candidate,
    clippy::similar_names,
    clippy::too_many_lines,
    clippy::unreadable_literal,
    clippy::unseparated_literal_suffix,
    clippy::wildcard_imports
)]

mod buffer;
mod common;
mod d2s;
#[cfg(not(feature = "small"))]
mod d2s_full_table;
mod d2s_intrinsics;
#[cfg(feature = "small")]
mod d2s_small_table;
mod digit_table;
mod f2s;
mod f2s_intrinsics;
mod pretty;

pub use crate::buffer::{Buffer, Float};

/// Unsafe functions that mirror the API of the C implementation of Ryū.
pub mod raw {
    pub use crate::pretty::{format32, format64};
}

<MSG> Get clippy clean

<DFF> @@ -1,3 +1,13 @@
+#![cfg_attr(
+    feature = "cargo-clippy",
+    allow(
+        cast_lossless,
+        cyclomatic_complexity,
+        many_single_char_names,
+        unreadable_literal,
+    )
+)]
+
 mod common;
 mod d2s;
 mod d2s_full_table;

{'commit': 'diff --git a/src/d2s.rs b/src/d2s.rs\nindex e38b40f..ffef781 100644\n--- a/src/d2s.rs\n+++ b/src/d2s.rs\n@@ -196,16 +196,14 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize {\n             // Only one of mp, mv, and mm can be a multiple of 5, if any.\n             if mv % 5 == 0 {\n                 vr_is_trailing_zeros = multiple_of_power_of_5(mv, q);\n+            } else if accept_bounds {\n+                // Same as min(e2 + (~mm & 1), pow5_factor(mm)) >= q\n+                // <=> e2 + (~mm & 1) >= q && pow5_factor(mm) >= q\n+                // <=> true && pow5_factor(mm) >= q, since e2 >= q.\n+                vm_is_trailing_zeros = multiple_of_power_of_5(mv - 1 - mm_shift as u64, q);\n             } else {\n-                if accept_bounds {\n-                    // Same as min(e2 + (~mm & 1), pow5_factor(mm)) >= q\n-                    // <=> e2 + (~mm & 1) >= q && pow5_factor(mm) >= q\n-                    // <=> true && pow5_factor(mm) >= q, since e2 >= q.\n-                    vm_is_trailing_zeros = multiple_of_power_of_5(mv - 1 - mm_shift as u64, q);\n-                } else {\n-                    // Same as min(e2 + 1, pow5_factor(mp)) >= q.\n-                    vp -= multiple_of_power_of_5(mv + 2, q) as u64;\n-                }\n+                // Same as min(e2 + 1, pow5_factor(mp)) >= q.\n+                vp -= multiple_of_power_of_5(mv + 2, q) as u64;\n             }\n         }\n     } else {\n@@ -244,9 +242,8 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize {\n     // Step 4: Find the shortest decimal representation in the interval of legal representations.\n     let mut removed = 0u32;\n     let mut last_removed_digit = 0u8;\n-    let output: u64;\n     // On average, we remove ~2 digits.\n-    if vm_is_trailing_zeros || vr_is_trailing_zeros {\n+    let output = if vm_is_trailing_zeros || vr_is_trailing_zeros {\n         // General case, which happens rarely (<1%).\n         while vp / 10 > vm / 10 {\n             vm_is_trailing_zeros &= vm - (vm / 10) * 10 == 0;\n@@ -272,8 +269,8 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize {\n             last_removed_digit = 4;\n         }\n         // We need to take vr+1 if vr is outside bounds or we need to round up.\n-        output = vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros))\n-            || (last_removed_digit >= 5)) as u64;\n+        vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros)) || (last_removed_digit >= 5))\n+            as u64\n     } else {\n         // Specialized for the common case (>99%).\n         while vp / 10 > vm / 10 {\n@@ -284,8 +281,8 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize {\n             removed += 1;\n         }\n         // We need to take vr+1 if vr is outside bounds or we need to round up.\n-        output = vr + ((vr == vm) || (last_removed_digit >= 5)) as u64;\n-    }\n+        vr + ((vr == vm) || (last_removed_digit >= 5)) as u64\n+    };\n     // The average output length is 16.38 digits.\n     let olength = decimal_length(output);\n     let vplength = olength + removed;\ndiff --git a/src/f2s.rs b/src/f2s.rs\nindex fb6d7d7..72f24b2 100644\n--- a/src/f2s.rs\n+++ b/src/f2s.rs\n@@ -251,12 +251,10 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize {\n             // Only one of mp, mv, and mm can be a multiple of 5, if any.\n             if mv % 5 == 0 {\n                 vr_is_trailing_zeros = multiple_of_power_of_5(mv, q);\n+            } else if accept_bounds {\n+                vm_is_trailing_zeros = multiple_of_power_of_5(mm, q);\n             } else {\n-                if accept_bounds {\n-                    vm_is_trailing_zeros = multiple_of_power_of_5(mm, q);\n-                } else {\n-                    vp -= multiple_of_power_of_5(mp, q) as u32;\n-                }\n+                vp -= multiple_of_power_of_5(mp, q) as u32;\n             }\n         }\n     } else {\n@@ -287,8 +285,7 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize {\n \n     // Step 4: Find the shortest decimal representation in the interval of legal representations.\n     let mut removed = 0u32;\n-    let mut output: u32;\n-    if vm_is_trailing_zeros || vr_is_trailing_zeros {\n+    let mut output = if vm_is_trailing_zeros || vr_is_trailing_zeros {\n         // General case, which happens rarely.\n         while vp / 10 > vm / 10 {\n             vm_is_trailing_zeros &= vm % 10 == 0;\n@@ -314,8 +311,8 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize {\n             last_removed_digit = 4;\n         }\n         // We need to take vr+1 if vr is outside bounds or we need to round up.\n-        output = vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros))\n-            || (last_removed_digit >= 5)) as u32;\n+        vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros)) || (last_removed_digit >= 5))\n+            as u32\n     } else {\n         // Common case.\n         while vp / 10 > vm / 10 {\n@@ -326,8 +323,8 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize {\n             removed += 1;\n         }\n         // We need to take vr+1 if vr is outside bounds or we need to round up.\n-        output = vr + ((vr == vm) || (last_removed_digit >= 5)) as u32;\n-    }\n+        vr + ((vr == vm) || (last_removed_digit >= 5)) as u32\n+    };\n     let olength = decimal_length(output);\n     let vplength = olength + removed;\n     let mut exp = e10 + vplength as i32 - 1;\ndiff --git a/src/lib.rs b/src/lib.rs\nindex c3da646..5956a18 100644\n--- a/src/lib.rs\n+++ b/src/lib.rs\n@@ -1,3 +1,13 @@\n+#![cfg_attr(\n+    feature = "cargo-clippy",\n+    allow(\n+        cast_lossless,\n+        cyclomatic_complexity,\n+        many_single_char_names,\n+        unreadable_literal,\n+    )\n+)]\n+\n mod common;\n mod d2s;\n mod d2s_full_table;\n', 'commit_subject': 'Get clippy clean', 'repo_name': 'dtolnay/ryu', 'committer': {'name': 'David Tolnay', 'email': '1480464b87745a0822a0e8b7545ca981d8e7352e@gmail.com', 'time_sec': '1532840245', 'tz_offset': '-420', 'date': {'seconds': '1532840245'}}, 'commit_tree': '8ba59d07e6e0dfe14f9c5af61e76d37fa8e5da2e', 'commit_message': 'Get clippy clean\n', 'language_name': 'Rust', 'license': 'apache-2.0', 'hunks': '@@ -1,3 +1,13 @@\n+#![cfg_attr(\n+    feature = "cargo-clippy",\n+    allow(\n+        cast_lossless,\n+        cyclomatic_complexity,\n+        many_single_char_names,\n+        unreadable_literal,\n+    )\n+)]\n+\n mod common;\n mod d2s;\n mod d2s_full_table;\n', 'addition_count': 10, 'deletion_count': 0, 'src_file': 'a/src/lib.rs', 'tgt_file': 'b/src/lib.rs', 'file_extension': '.rs', 'before_file': 'mod common;\nmod d2s;\nmod d2s_full_table;\n//! available under the creative commons CC-BY-SA license.\n//!\n//! This Rust implementation is a line-by-line port of Ulf Adams\' implementation\n//! in C, [https://github.com/ulfjack/ryu][upstream].\n//!\n//! [paper]: https://dl.acm.org/citation.cfm?id=3192369\n//! [upstream]: https://github.com/ulfjack/ryu\n//!\n//! # Example\n//!\n//! ```\n//! fn main() {\n//!     let mut buffer = ryu::Buffer::new();\n//!     let printed = buffer.format(1.234);\n//!     assert_eq!(printed, "1.234");\n//! }\n//! ```\n//!\n//! ## Performance (lower is better)\n//!\n//! ![performance](https://raw.githubusercontent.com/dtolnay/ryu/master/performance.png)\n//!\n//! You can run upstream\'s benchmarks with:\n//!\n//! ```console\n//! $ git clone https://github.com/ulfjack/ryu c-ryu\n//! $ cd c-ryu\n//! $ bazel run -c opt //ryu/benchmark\n//! ```\n//!\n//! And the same benchmark against our implementation with:\n//!\n//! ```console\n//! $ git clone https://github.com/dtolnay/ryu rust-ryu\n//! $ cd rust-ryu\n//! $ cargo run --example upstream_benchmark --release\n//! ```\n//!\n//! These benchmarks measure the average time to print a 32-bit float and average\n//! time to print a 64-bit float, where the inputs are distributed as uniform random\n//! bit patterns 32 and 64 bits wide.\n//!\n//! The upstream C code, the unsafe direct Rust port, and the safe pretty Rust API\n//! all perform the same, taking around 21 nanoseconds to format a 32-bit float and\n//! 31 nanoseconds to format a 64-bit float.\n//!\n//! There is also a Rust-specific benchmark comparing this implementation to the\n//! standard library which you can run with:\n//!\n//! ```console\n//! $ cargo bench\n//! ```\n//!\n//! The benchmark shows Ryū approximately 2-5x faster than the standard library\n//! across a range of f32 and f64 inputs. Measurements are in nanoseconds per\n//! iteration; smaller is better.\n//!\n//! ## Formatting\n//!\n//! This library tends to produce more human-readable output than the standard\n//! library\'s to\\_string, which never uses scientific notation. Here are two\n//! examples:\n//!\n//! - *ryu:* 1.23e40, *std:* 12300000000000000000000000000000000000000\n//! - *ryu:* 1.23e-40, *std:* 0.000000000000000000000000000000000000000123\n//!\n//! Both libraries print short decimals such as 0.0000123 without scientific\n//! notation.\n\n#![no_std]\n#![doc(html_root_url = "https://docs.rs/ryu/1.0.11")]\n#![allow(\n    clippy::cast_lossless,\n    clippy::cast_possible_truncation,\n    clippy::cast_possible_wrap,\n    clippy::cast_sign_loss,\n    clippy::checked_conversions,\n    clippy::doc_markdown,\n    clippy::expl_impl_clone_on_copy,\n    clippy::if_not_else,\n    clippy::many_single_char_names,\n    clippy::missing_panics_doc,\n    clippy::module_name_repetitions,\n    clippy::must_use_candidate,\n    clippy::similar_names,\n    clippy::too_many_lines,\n    clippy::unreadable_literal,\n    clippy::unseparated_literal_suffix,\n    clippy::wildcard_imports\n)]\n\nmod buffer;\nmod common;\nmod d2s;\n#[cfg(not(feature = "small"))]\nmod d2s_full_table;\nmod d2s_intrinsics;\n#[cfg(feature = "small")]\nmod d2s_small_table;\nmod digit_table;\nmod f2s;\nmod f2s_intrinsics;\nmod pretty;\n\npub use crate::buffer::{Buffer, Float};\n\n/// Unsafe functions that mirror the API of the C implementation of Ryū.\npub mod raw {\n    pub use crate::pretty::{format32, format64};\n}\n', 'message': 'Get clippy clean\n', 'author_name': 'David Tolnay', 'lang': 'rs'}