From 9e3ae8a8961032b091c110f05bbff8f360e6a678 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 28 Jul 2018 21:54:57 -0700 Subject: [PATCH] Get clippy clean --- src/d2s.rs | 27 ++++++++++++--------------- src/f2s.rs | 19 ++++++++----------- src/lib.rs | 10 ++++++++++ 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/d2s.rs b/src/d2s.rs index e38b40f..ffef781 100644 --- a/src/d2s.rs +++ b/src/d2s.rs @@ -196,16 +196,14 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { // Only one of mp, mv, and mm can be a multiple of 5, if any. if mv % 5 == 0 { vr_is_trailing_zeros = multiple_of_power_of_5(mv, q); + } else if accept_bounds { + // Same as min(e2 + (~mm & 1), pow5_factor(mm)) >= q + // <=> e2 + (~mm & 1) >= q && pow5_factor(mm) >= q + // <=> true && pow5_factor(mm) >= q, since e2 >= q. + vm_is_trailing_zeros = multiple_of_power_of_5(mv - 1 - mm_shift as u64, q); } else { - if accept_bounds { - // Same as min(e2 + (~mm & 1), pow5_factor(mm)) >= q - // <=> e2 + (~mm & 1) >= q && pow5_factor(mm) >= q - // <=> true && pow5_factor(mm) >= q, since e2 >= q. - vm_is_trailing_zeros = multiple_of_power_of_5(mv - 1 - mm_shift as u64, q); - } else { - // Same as min(e2 + 1, pow5_factor(mp)) >= q. - vp -= multiple_of_power_of_5(mv + 2, q) as u64; - } + // Same as min(e2 + 1, pow5_factor(mp)) >= q. + vp -= multiple_of_power_of_5(mv + 2, q) as u64; } } } else { @@ -244,9 +242,8 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { // Step 4: Find the shortest decimal representation in the interval of legal representations. let mut removed = 0u32; let mut last_removed_digit = 0u8; - let output: u64; // On average, we remove ~2 digits. - if vm_is_trailing_zeros || vr_is_trailing_zeros { + let output = if vm_is_trailing_zeros || vr_is_trailing_zeros { // General case, which happens rarely (<1%). while vp / 10 > vm / 10 { vm_is_trailing_zeros &= vm - (vm / 10) * 10 == 0; @@ -272,8 +269,8 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { last_removed_digit = 4; } // We need to take vr+1 if vr is outside bounds or we need to round up. - output = vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros)) - || (last_removed_digit >= 5)) as u64; + vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros)) || (last_removed_digit >= 5)) + as u64 } else { // Specialized for the common case (>99%). while vp / 10 > vm / 10 { @@ -284,8 +281,8 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { removed += 1; } // We need to take vr+1 if vr is outside bounds or we need to round up. - output = vr + ((vr == vm) || (last_removed_digit >= 5)) as u64; - } + vr + ((vr == vm) || (last_removed_digit >= 5)) as u64 + }; // The average output length is 16.38 digits. let olength = decimal_length(output); let vplength = olength + removed; diff --git a/src/f2s.rs b/src/f2s.rs index fb6d7d7..72f24b2 100644 --- a/src/f2s.rs +++ b/src/f2s.rs @@ -251,12 +251,10 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize { // Only one of mp, mv, and mm can be a multiple of 5, if any. if mv % 5 == 0 { vr_is_trailing_zeros = multiple_of_power_of_5(mv, q); + } else if accept_bounds { + vm_is_trailing_zeros = multiple_of_power_of_5(mm, q); } else { - if accept_bounds { - vm_is_trailing_zeros = multiple_of_power_of_5(mm, q); - } else { - vp -= multiple_of_power_of_5(mp, q) as u32; - } + vp -= multiple_of_power_of_5(mp, q) as u32; } } } else { @@ -287,8 +285,7 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize { // Step 4: Find the shortest decimal representation in the interval of legal representations. let mut removed = 0u32; - let mut output: u32; - if vm_is_trailing_zeros || vr_is_trailing_zeros { + let mut output = if vm_is_trailing_zeros || vr_is_trailing_zeros { // General case, which happens rarely. while vp / 10 > vm / 10 { vm_is_trailing_zeros &= vm % 10 == 0; @@ -314,8 +311,8 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize { last_removed_digit = 4; } // We need to take vr+1 if vr is outside bounds or we need to round up. - output = vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros)) - || (last_removed_digit >= 5)) as u32; + vr + ((vr == vm && (!accept_bounds || !vm_is_trailing_zeros)) || (last_removed_digit >= 5)) + as u32 } else { // Common case. while vp / 10 > vm / 10 { @@ -326,8 +323,8 @@ pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize { removed += 1; } // We need to take vr+1 if vr is outside bounds or we need to round up. - output = vr + ((vr == vm) || (last_removed_digit >= 5)) as u32; - } + vr + ((vr == vm) || (last_removed_digit >= 5)) as u32 + }; let olength = decimal_length(output); let vplength = olength + removed; let mut exp = e10 + vplength as i32 - 1; diff --git a/src/lib.rs b/src/lib.rs index c3da646..5956a18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;