Skip to content

Commit 1838797

Browse files
asder8215sylvestre
authored andcommitted
rollback converting from big_uint to u128
1 parent deaf517 commit 1838797

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/uu/factor/src/factor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ fn print_factors_str(
4545
}
4646
// use num_prime's factorize128 algorithm for u128 integers
4747
else if x <= BigUint::from_u128(u128::MAX).unwrap() {
48-
// if it's a u128 integer, BigUint will have two u64 digits
49-
// in its Vec<u64>, which index 0 is treated as u64::MAX
50-
let big_uint_u64s = x.clone().to_u64_digits();
51-
let x = u64::MAX as u128 + big_uint_u64s[1] as u128;
48+
let rx = num_str.trim().parse::<u128>();
49+
let Ok(x) = rx else {
50+
// return Ok(). it's non-fatal and we should try the next number.
51+
show_warning!("{}: {}", num_str.maybe_quote(), rx.unwrap_err());
52+
set_exit_code(1);
53+
return Ok(());
54+
};
5255
let prime_factors = num_prime::nt_funcs::factorize128(x);
5356
write_result_u128(w, &x, prime_factors, print_exponents)
5457
.map_err_context(|| translate!("factor-error-write-error"))?;

0 commit comments

Comments
 (0)