Skip to content

Commit eccfc0e

Browse files
committed
Clean up interval div
1 parent fb3b89c commit eccfc0e

File tree

3 files changed

+16
-48
lines changed

3 files changed

+16
-48
lines changed

src/cdomain/value/cdomains/int/intervalDomain.ml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,24 +294,13 @@ struct
294294
match x, y with
295295
| None, None -> (bot (),{underflow=false; overflow=false})
296296
| None, _ | _, None -> raise (ArithmeticOnIntegerBot (Printf.sprintf "%s op %s" (show x) (show y)))
297-
| (Some ((x1,x2) as x)), (Some ((y1,y2) as y)) ->
298-
begin
299-
let (r, ov) =
300-
let (n, p) = IArith.div x y in
301-
norm ik (join_no_norm ik n p) (* normal join drops overflow info *)
302-
in
303-
if leq (of_int ik (Ints_t.zero) |> fst) (Some (y1,y2)) then
304-
(top_of ik, ov)
305-
else
306-
(r, ov)
307-
(* let is_zero v = Ints_t.compare v Ints_t.zero = 0 in
308-
match y1, y2 with
309-
| l, u when is_zero l && is_zero u -> (top_of ik,{underflow=false; overflow=false})
310-
| l, _ when is_zero l -> div ik (Some (x1,x2)) (Some (Ints_t.one,y2))
311-
| _, u when is_zero u -> div ik (Some (x1,x2)) (Some (y1, Ints_t.(neg one)))
312-
(* | _ when leq (of_int ik (Ints_t.zero) |> fst) (Some (y1,y2)) -> (top_of ik,{underflow=false; overflow=false}) *)
313-
| _ -> binary_op_with_norm IArith.div ik x y *)
314-
end
297+
| Some x, Some y ->
298+
let (neg, pos) = IArith.div x y in
299+
let (r, ov) = norm ik (join_no_norm ik neg pos) in (* normal join drops overflow info *)
300+
if leq (of_int ik Ints_t.zero |> fst) (Some y) then
301+
(top_of ik, ov)
302+
else
303+
(r, ov)
315304

316305
let ne ik x y =
317306
match x, y with

src/cdomain/value/cdomains/int/intervalSetDomain.ml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,25 +363,15 @@ struct
363363
let neg ?no_ov = unary_op_with_norm IArith.neg
364364

365365
let div ?no_ov ik x y =
366-
let rec interval_div x ((y1, y2) as y) = begin
367-
let top_of ik = top_of ik |> List.hd in
368-
let r =
369-
let (n, p) = IArith.div x y in
370-
List.filter_map Fun.id [n; p]
371-
in
372-
if leq (of_int ik (Ints_t.zero) |> fst) ([(y1,y2)]) then
373-
[top_of ik]
374-
else
375-
r (* should always be singleton, because if there's a negative and a positive side, then it must've included zero, which is already handled by previous case *)
376-
(* let is_zero v = v =. Ints_t.zero in
377-
match y1, y2 with
378-
| l, u when is_zero l && is_zero u -> top_of ik
379-
| l, _ when is_zero l -> interval_div x (Ints_t.one,y2)
380-
| _, u when is_zero u -> interval_div x (y1, Ints_t.(neg one))
381-
| _ when leq (of_int ik (Ints_t.zero) |> fst) ([(y1,y2)]) -> top_of ik
382-
| _ -> IArith.div x (y1, y2) *)
383-
end
384-
in binary_op_concat_with_norm interval_div ik x y
366+
let rec interval_div x y =
367+
if leq (of_int ik Ints_t.zero |> fst) [y] then
368+
top_of ik (* TODO: should somehow handle overflow like normal intervals? *)
369+
else (
370+
let (neg, pos) = IArith.div x y in
371+
List.filter_map Fun.id [neg; pos] (* should always be singleton, because if there's a negative and a positive side, then it must've included zero, which is already handled by previous case *)
372+
)
373+
in
374+
binary_op_concat_with_norm interval_div ik x y
385375

386376
let rem ik x y =
387377
let interval_rem (x, y) =

src/cdomain/value/cdomains/intDomain0.ml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,6 @@ module IntervalArith (Ints_t : IntOps.IntOps) = struct
361361
let y2p = Ints_t.shift_left Ints_t.one y2 in
362362
mul (x1, x2) (y1p, y2p)
363363

364-
let div (x1, x2) (y1, y2) =
365-
let x1y1n = (Ints_t.div x1 y1) in
366-
let x1y2n = (Ints_t.div x1 y2) in
367-
let x2y1n = (Ints_t.div x2 y1) in
368-
let x2y2n = (Ints_t.div x2 y2) in
369-
let x1y1p = (Ints_t.div x1 y1) in
370-
let x1y2p = (Ints_t.div x1 y2) in
371-
let x2y1p = (Ints_t.div x2 y1) in
372-
let x2y2p = (Ints_t.div x2 y2) in
373-
(min4 x1y1n x1y2n x2y1n x2y2n, max4 x1y1p x1y2p x2y1p x2y2p)
374-
375364
let div (a, b) (c, d) =
376365
let pos =
377366
if Ints_t.(compare one d) <= 0 then

0 commit comments

Comments
 (0)