Section Znearest.
(** Roundings to nearest: when in the middle, use the choice function *)
Variable choice : Z -> bool.
Definition Znearest x :=
match Rcompare (x - IZR (Zfloor x)) (/2) with
| Lt => Zfloor x
| Eq => if choice (Zfloor x) then Zceil x else Zfloor x
| Gt => Zceil x
end.
Global Instance valid_rnd_N : Valid_rnd Znearest.

Theorem round_N_middle :
forall x,
(x - round Zfloor x = round Zceil x - x)%R ->
round Znearest x = if choice (Zfloor (scaled_mantissa x)) then round Zceil x else round Zfloor x.