[Nickle] nickle: Branch 'master'
Keith Packard
keithp at keithp.com
Thu Oct 16 10:32:30 PDT 2025
gamma.5c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
New commits:
commit 1b804612c6939bb0038ad7416c44f6f2341e44ec
Author: Keith Packard <keithp at keithp.com>
Date: Thu Oct 16 10:29:38 2025 -0700
Raise exception for gamma for all non-positive integers
Instead of relying on representation to detect non-positive integers, check
to see if the value equals its own floor instead.
Also, as a minor cleanup, don't subtract 1 from the argument to
Stieltjes only to have 1 added back in that function.
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/gamma.5c b/gamma.5c
index 17dc9cb..f2a2cbf 100644
--- a/gamma.5c
+++ b/gamma.5c
@@ -59,7 +59,7 @@ extend namespace Math {
return (real[len]) { [k] = m[0,k] };
}
- real N = imprecise(n + 1, bits);
+ real N = imprecise(n, bits);
real q = N;
real[*] c = StieltjesCF(ord, bits);
real one = imprecise(1, bits);
@@ -69,13 +69,16 @@ extend namespace Math {
}
/*
- * For positive integers, just use factorial
+ * For non-positive integers, raise exception
*/
- if (is_int(n)) {
- if (n <= 0)
- raise invalid_argument("gamma of non-positive integer", 0, n);
+ if (n <= 0 && n == floor(n))
+ raise invalid_argument("gamma of non-positive integer", 0, n);
+
+ /*
+ * For positive integers, use factorial
+ */
+ if (is_int(n))
return (floor(n)-1)!;
- }
n = imprecise(n);
int bits = precision(n);
@@ -123,7 +126,7 @@ extend namespace Math {
* don't know how much smaller
*/
int ord = ceil(bits / 20);
- return imprecise(Stieltjes(n-1, ord, bits + 20), bits);
+ return imprecise(Stieltjes(n, ord, bits + 20), bits);
}
public real(real n) Γ = gamma;
More information about the Nickle
mailing list