Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make cil_exp_of_linexpr1 work with fractional expressions #1493

Merged
merged 11 commits into from
Jul 2, 2024
14 changes: 7 additions & 7 deletions src/cdomains/apron/sharedFunctions.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ let int_of_scalar ?round (scalar: Scalar.t) =
| None when Stdlib.Float.is_integer f -> Some f
| None -> None
in
Z.of_float f
Q.make (Z.of_float f) Z.one
| Mpqf scalar -> (* octMPQ, boxMPQ, polkaMPQ *)
let n = Mpqf.get_num scalar in
let d = Mpqf.get_den scalar in
let+ z =
let+ (n,d) =
if Mpzf.cmp_int d 1 = 0 then (* exact integer (denominator 1) *)
Some n
Some (n,Mpzf.of_int 1)
else
begin match round with
| Some `Floor -> Some (Mpzf.fdiv_q n d) (* floor division *)
| Some `Ceil -> Some (Mpzf.cdiv_q n d) (* ceiling division *)
| None -> None
| Some `Floor -> Some (Mpzf.fdiv_q n d, Mpzf.of_int 1) (* floor division *)
| Some `Ceil -> Some (Mpzf.cdiv_q n d, Mpzf.of_int 1) (* ceiling division *)
| None -> Some (n,d)
end
in
Z_mlgmpidl.z_of_mpzf z
Q.make (Z_mlgmpidl.z_of_mpzf n) (Z_mlgmpidl.z_of_mpzf d)
| _ ->
failwith ("int_of_scalar: unsupported: " ^ Scalar.to_string scalar)

Expand Down