Skip to content

Commit b252f12

Browse files
Handle zero and negative values in adjust_approximate
1 parent 25250fe commit b252f12

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

factorion-math/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,13 @@ pub fn approximate_termial_digits_float(k: u32, n: Float) -> Integer {
336336
/// Adjusts the output of [`approximate_factorial`], by combining the 10 exponents of the number and the extra exponent.
337337
///
338338
/// # Panic
339-
/// Will panic if `x` is not finite or `x` is non-positive.
339+
/// Will panic if `x` is not finite.
340340
pub fn adjust_approximate((x, e): (Float, Integer)) -> (Float, Integer) {
341-
assert!(x > 0.0, "Got non-positive number, x was {x}");
342341
let prec = x.prec();
343-
let (extra, _) = (x.clone().ln() / Float::with_val(prec, 10).ln())
342+
if x == 0.0 {
343+
return (Float::with_val(prec, 0), Integer::ZERO.clone());
344+
}
345+
let (extra, _) = (x.clone().abs().ln() / Float::with_val(prec, 10).ln())
344346
.to_integer_round(rug::float::Round::Down)
345347
.unwrap_or_else(|| panic!("Got non-finite number, x was {x}"));
346348
let x = x / (Float::with_val(prec, 10).pow(extra.clone()));

0 commit comments

Comments
 (0)