mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
uucore: format: num_parser: Make it clear that scale can only be positive
After scratching my head a bit about why the hexadecimal code works, seems better to do make scale an u64 to clarify. Note that this may u64 may exceed i64 capacity, but that can only happen if the number of digits provided > 2**63 (impossible).
This commit is contained in:
parent
bd68eb8beb
commit
30c89af9ac
1 changed files with 2 additions and 2 deletions
|
@ -268,7 +268,7 @@ fn parse(
|
|||
// Parse the integral part of the number
|
||||
let mut chars = rest.chars().enumerate().fuse().peekable();
|
||||
let mut digits = BigUint::zero();
|
||||
let mut scale = 0i64;
|
||||
let mut scale = 0u64;
|
||||
let mut exponent = 0i64;
|
||||
while let Some(d) = chars.peek().and_then(|&(_, c)| base.digit(c)) {
|
||||
chars.next();
|
||||
|
@ -335,7 +335,7 @@ fn parse(
|
|||
let bd = if scale == 0 && exponent == 0 {
|
||||
BigDecimal::from_bigint(signed_digits, 0)
|
||||
} else if base == Base::Decimal {
|
||||
BigDecimal::from_bigint(signed_digits, scale - exponent)
|
||||
BigDecimal::from_bigint(signed_digits, scale as i64 - exponent)
|
||||
} else if base == Base::Hexadecimal {
|
||||
// Base is 16, init at scale 0 then divide by base**scale.
|
||||
let bd = BigDecimal::from_bigint(signed_digits, 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue