From a748e528f04493f83a317ab968a3a5d0b2804a88 Mon Sep 17 00:00:00 2001 From: zyc <109252977+YichiZhang0613@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:14:27 +0800 Subject: [PATCH 1/3] Fix wrong comment and add assertion --- factorion-math/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/factorion-math/src/lib.rs b/factorion-math/src/lib.rs index e14c99d..f1c4cee 100644 --- a/factorion-math/src/lib.rs +++ b/factorion-math/src/lib.rs @@ -336,8 +336,9 @@ pub fn approximate_termial_digits_float(k: u32, n: Float) -> Integer { /// Adjusts the output of [`approximate_factorial`], by combining the 10 exponents of the number and the extra exponent. /// /// # Panic -/// Will panic if `x` is not finite. +/// Will panic if `x` is not finite or `x` is non-positive. pub fn adjust_approximate((x, e): (Float, Integer)) -> (Float, Integer) { + assert!(x > 0.0, "Got non-positive number, x was {x}"); let prec = x.prec(); let (extra, _) = (x.clone().ln() / Float::with_val(prec, 10).ln()) .to_integer_round(rug::float::Round::Down) From 25250fe6066fdb7824dc24f70fde64c97ae0cde6 Mon Sep 17 00:00:00 2001 From: zyc <109252977+YichiZhang0613@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:21:40 +0800 Subject: [PATCH 2/3] bump version to 1.0.4 --- Cargo.lock | 2 +- factorion-math/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 912fe0c..7c2496a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -447,7 +447,7 @@ dependencies = [ [[package]] name = "factorion-math" -version = "1.0.3" +version = "1.0.4" dependencies = [ "gmp-mpfr-sys", "rug", diff --git a/factorion-math/Cargo.toml b/factorion-math/Cargo.toml index 2d3a054..6cd65d6 100644 --- a/factorion-math/Cargo.toml +++ b/factorion-math/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factorion-math" -version = "1.0.3" +version = "1.0.4" edition = "2024" description = "The math (factorials and related functions) used by factorion" license = "MIT" From b252f12abf8ec184537b272b1a578c8c0957ce82 Mon Sep 17 00:00:00 2001 From: zyc <109252977+YichiZhang0613@users.noreply.github.com> Date: Thu, 26 Mar 2026 11:29:29 +0800 Subject: [PATCH 3/3] Handle zero and negative values in adjust_approximate --- factorion-math/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/factorion-math/src/lib.rs b/factorion-math/src/lib.rs index f1c4cee..9884072 100644 --- a/factorion-math/src/lib.rs +++ b/factorion-math/src/lib.rs @@ -336,11 +336,13 @@ pub fn approximate_termial_digits_float(k: u32, n: Float) -> Integer { /// Adjusts the output of [`approximate_factorial`], by combining the 10 exponents of the number and the extra exponent. /// /// # Panic -/// Will panic if `x` is not finite or `x` is non-positive. +/// Will panic if `x` is not finite. pub fn adjust_approximate((x, e): (Float, Integer)) -> (Float, Integer) { - assert!(x > 0.0, "Got non-positive number, x was {x}"); let prec = x.prec(); - let (extra, _) = (x.clone().ln() / Float::with_val(prec, 10).ln()) + if x == 0.0 { + return (Float::with_val(prec, 0), Integer::ZERO.clone()); + } + let (extra, _) = (x.clone().abs().ln() / Float::with_val(prec, 10).ln()) .to_integer_round(rug::float::Round::Down) .unwrap_or_else(|| panic!("Got non-finite number, x was {x}")); let x = x / (Float::with_val(prec, 10).pow(extra.clone()));