Skip to content

Commit 3d8ef6b

Browse files
committed
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).
1 parent bc67efe commit 3d8ef6b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/uucore/src/lib/features/format/num_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn parse(
268268
// Parse the integral part of the number
269269
let mut chars = rest.chars().enumerate().fuse().peekable();
270270
let mut digits = BigUint::zero();
271-
let mut scale = 0i64;
271+
let mut scale = 0u64;
272272
let mut exponent = 0i64;
273273
while let Some(d) = chars.peek().and_then(|&(_, c)| base.digit(c)) {
274274
chars.next();
@@ -335,7 +335,7 @@ fn parse(
335335
let bd = if scale == 0 && exponent == 0 {
336336
BigDecimal::from_bigint(signed_digits, 0)
337337
} else if base == Base::Decimal {
338-
BigDecimal::from_bigint(signed_digits, scale - exponent)
338+
BigDecimal::from_bigint(signed_digits, scale as i64 - exponent)
339339
} else if base == Base::Hexadecimal {
340340
// Base is 16, init at scale 0 then divide by base**scale.
341341
let bd = BigDecimal::from_bigint(signed_digits, 0)

0 commit comments

Comments
 (0)