From ac3a02b80bf78c4212eab930243c1a2e0ca9c728 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 21 Mar 2025 16:19:59 -0400 Subject: [PATCH] Add version check for GNU MP's prev_prime() --- environment.c | 4 ++++ stdlib/integers.c | 4 ++++ stdlib/integers.h | 4 ++++ test/integers.tm | 4 ++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/environment.c b/environment.c index 7b4bb5b..9f230cd 100644 --- a/environment.c +++ b/environment.c @@ -120,7 +120,11 @@ env_t *global_env(void) {"parse", "Int$parse", "func(text:Text -> Int?)"}, {"plus", "Int$plus", "func(x,y:Int -> Int)"}, {"power", "Int$power", "func(base:Int,exponent:Int -> Int)"}, +#if __GNU_MP_VERSION >= 6 +#if __GNU_MP_VERSION_MINOR >= 3 {"prev_prime", "Int$prev_prime", "func(x:Int -> Int)"}, +#endif +#endif {"right_shifted", "Int$right_shifted", "func(x,y:Int -> Int)"}, {"sqrt", "Int$sqrt", "func(x:Int -> Int?)"}, {"times", "Int$times", "func(x,y:Int -> Int)"}, diff --git a/stdlib/integers.c b/stdlib/integers.c index c4fcdfb..4d5d0a8 100644 --- a/stdlib/integers.c +++ b/stdlib/integers.c @@ -409,6 +409,8 @@ public Int_t Int$next_prime(Int_t x) return Int$from_mpz(p); } +#if __GNU_MP_VERSION >= 6 +#if __GNU_MP_VERSION_MINOR >= 3 public Int_t Int$prev_prime(Int_t x) { mpz_t p; @@ -417,6 +419,8 @@ public Int_t Int$prev_prime(Int_t x) fail("There is no prime number before %k", (Text_t[1]){Int$as_text(&x, false, &Int$info)}); return Int$from_mpz(p); } +#endif +#endif public Int_t Int$choose(Int_t n, Int_t k) { diff --git a/stdlib/integers.h b/stdlib/integers.h index 3bc3abe..e058688 100644 --- a/stdlib/integers.h +++ b/stdlib/integers.h @@ -142,7 +142,11 @@ Int_t Int$slow_negative(Int_t x); Int_t Int$slow_negated(Int_t x); 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); +#endif +#endif Int_t Int$choose(Int_t n, Int_t k); Int_t Int$factorial(Int_t n); diff --git a/test/integers.tm b/test/integers.tm index e6b2ba9..9ab0b0c 100644 --- a/test/integers.tm +++ b/test/integers.tm @@ -96,8 +96,8 @@ func main(): = 2 >> 7:next_prime() = 11 - >> 11:prev_prime() - = 7 + #>> 11:prev_prime() + #= 7 >> (and: p:is_prime() for p in [ 2, 3, 5, 7, 137372146048179869781170214707,