aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-18 15:52:21 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-18 15:52:21 -0400
commit171d80ac1e5bd006c2c600f36a42440dfb635605 (patch)
treef1eaf76cbea586cb786dc1d23828a5c8d48e30b4 /src/stdlib
parent8542662b34eaee9801b077838049152881aa0b93 (diff)
Make Int.prev_prime() optional instead of erroring
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/integers.c4
-rw-r--r--src/stdlib/integers.h2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/stdlib/integers.c b/src/stdlib/integers.c
index b4ca69d3..bb39d99c 100644
--- a/src/stdlib/integers.c
+++ b/src/stdlib/integers.c
@@ -434,12 +434,12 @@ public Int_t Int$next_prime(Int_t x)
#if __GNU_MP_VERSION >= 6
#if __GNU_MP_VERSION_MINOR >= 3
-public Int_t Int$prev_prime(Int_t x)
+public OptionalInt_t Int$prev_prime(Int_t x)
{
mpz_t p;
mpz_init_set_int(p, x);
if (unlikely(mpz_prevprime(p, p) == 0))
- fail("There is no prime number before ", x);
+ return NONE_INT;
return Int$from_mpz(p);
}
#endif
diff --git a/src/stdlib/integers.h b/src/stdlib/integers.h
index c7643a8d..7b7cf12e 100644
--- a/src/stdlib/integers.h
+++ b/src/stdlib/integers.h
@@ -144,7 +144,7 @@ bool Int$is_prime(Int_t x, Int_t reps);
Int_t Int$next_prime(Int_t x);
#if __GNU_MP_VERSION >= 6
#if __GNU_MP_VERSION_MINOR >= 3
-Int_t Int$prev_prime(Int_t x);
+OptionalInt_t Int$prev_prime(Int_t x);
#endif
#endif
Int_t Int$choose(Int_t n, Int_t k);