From 355fb1b2d0ccf6454a82bcf04b3c356dbfb40fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Tue, 3 Sep 2024 21:59:26 +0200 Subject: [PATCH] C stub: fix precision range check #37 --- src/mlmpfr_stubs.c | 4 ++-- testsuite/initializationfunctions.ml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mlmpfr_stubs.c b/src/mlmpfr_stubs.c index 2143a47..8e37be9 100644 --- a/src/mlmpfr_stubs.c +++ b/src/mlmpfr_stubs.c @@ -38,8 +38,8 @@ precision_in_range (value prec) { int p = Int_val (prec); - if (p <= Int_val (caml_mpfr_prec_min ()) - || p >= Unsigned_int_val (caml_mpfr_prec_max ())) + if (p < Int_val (caml_mpfr_prec_min ()) + || p > Unsigned_int_val (caml_mpfr_prec_max ())) caml_raise_with_arg (*caml_named_value ("precision range exception"), Val_int (p)); } diff --git a/testsuite/initializationfunctions.ml b/testsuite/initializationfunctions.ml index 46b3ffd..d4b9faf 100644 --- a/testsuite/initializationfunctions.ml +++ b/testsuite/initializationfunctions.ml @@ -36,5 +36,7 @@ let _ = let x = M.make_zero M.Negative in printf "%s\n" (rounding_to_string x); printf "%d\n" (M.get_prec x); + (* Should not raise Precision_range exception *) + let _ = M.make_zero ~prec:M.mpfr_prec_min M.Positive in (); Gc.full_major () (* garbage collector full major *)