mirror of
https://github.com/openharmony/third_party_rust_ryu.git
synced 2026-07-20 03:23:32 -04:00
Get clippy clean
This commit is contained in:
+12
-15
@@ -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;
|
||||
|
||||
+8
-11
@@ -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;
|
||||
|
||||
+10
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user