Skip to content

flt2dec: replace for loop by iter_mut #144205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions library/core/src/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,19 @@ pub fn round_up(d: &mut [u8]) -> Option<u8> {
Some(i) => {
// d[i+1..n] is all nines
d[i] += 1;
for j in i + 1..d.len() {
d[j] = b'0';
}
d[i + 1..].fill(b'0');
None
}
None if d.len() > 0 => {
None if d.is_empty() => {
// an empty buffer rounds up (a bit strange but reasonable)
Some(b'1')
}
None => {
// 999..999 rounds to 1000..000 with an increased exponent
d[0] = b'1';
for j in 1..d.len() {
d[j] = b'0';
}
d[1..].fill(b'0');
Some(b'0')
}
None => {
// an empty buffer rounds up (a bit strange but reasonable)
Some(b'1')
}
}
}

Expand Down
Loading