Skip to content
Snippets Groups Projects
Commit a85a6e7b authored by Maxime Jacquemin's avatar Maxime Jacquemin
Browse files

[Integer] power_int_positive_int returns an option

This function relies on Z.power_int_positive_int, which can raise the
exception Invalid_argument when dealing with an exponent too big to
produce a valid result in GMP. This exception is now catched and thus
the function produce an option.

Modifications at callsites have been taken care of, and the file
floating_point.ml has been made more human readable.
parent 6ee3fd7a
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,9 @@ let two_power n =
else
two_power_of_int k
let power_int_positive_int = Big_int_Z.power_int_positive_int
let power_int_positive_int n e =
try Some (Big_int_Z.power_int_positive_int n e)
with Invalid_argument _ -> None
let popcount = Z.popcount
......
......@@ -203,7 +203,7 @@ val two_power : t -> t
val two_power_of_int : int -> t
(** Computes [2^n] *)
val power_int_positive_int: int -> int -> t
val power_int_positive_int: int -> int -> t option
(** Exponentiation *)
val extract_bits : start:t -> stop:t -> t -> t
......
This diff is collapsed.
......@@ -767,10 +767,9 @@ module Make
subvalues that are all evaluated. Limits the number of splits to
keep the number of evaluations linear on [nb]. *)
let subdivnb =
let pow n e = Integer.power_int_positive_int n e |> Option.get in
if nb > 3
then
let pow = Integer.power_int_positive_int in
(subdivnb * nb) / (Integer.to_int_exn (pow 2 (nb - 1)))
then (subdivnb * nb) / (Integer.to_int_exn (pow 2 (nb - 1)))
else subdivnb
in
Self.result ~current:true ~once:true ~dkey
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment