Skip to content

Commit

Permalink
C stub: fix precision range check #37
Browse files Browse the repository at this point in the history
  • Loading branch information
thvnx committed Sep 3, 2024
1 parent a356c25 commit 355fb1b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mlmpfr_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions testsuite/initializationfunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)

0 comments on commit 355fb1b

Please sign in to comment.