Commit 7fdaad84 authored by Guillaume Melquiond's avatar Guillaume Melquiond
Browse files

Do not adjust the remainder of computer_div_mod if it is zero.

This fixes (-2) mod 2 being evaluated as nonzero.
parent baae8180
...@@ -44,13 +44,13 @@ let euclidean_div x y = fst (euclidean_div_mod x y) ...@@ -44,13 +44,13 @@ let euclidean_div x y = fst (euclidean_div_mod x y)
let euclidean_mod x y = snd (euclidean_div_mod x y) let euclidean_mod x y = snd (euclidean_div_mod x y)
let computer_div_mod x y = let computer_div_mod x y =
let q,r = quomod_big_int x y in let (q,r) as qr = quomod_big_int x y in
(* we have x = q*y + r with 0 <= r < |y| *) (* we have x = q*y + r with 0 <= r < |y| *)
if sign x < 0 then if sign x >= 0 || sign r = 0 then qr
else
if sign y < 0 if sign y < 0
then (pred q, add r y) then (pred q, add r y)
else (succ q, sub r y) else (succ q, sub r y)
else (q,r)
let computer_div x y = fst (computer_div_mod x y) let computer_div x y = fst (computer_div_mod x y)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment