(** This file is part of the Flocq formalization of floating-point arithmetic in Coq: http://flocq.gforge.inria.fr/  Copyright (C) 2013-2018 Sylvie Boldo #<br /># Copyright (C) 2013-2018 Guillaume Melquiond  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the COPYING file for more details. *)
(** * Rounding to odd and its properties, including the equivalence between rnd_NE and double rounding with rnd_odd and then rnd_NE *)
Definition Zrnd_odd x :=  match Req_EM_T x (IZR (Zfloor x))  with
| left _   => Zfloor x
| right _  => match (Z.even (Zfloor x)) with
| true => Zceil x
| false => Zfloor x
end
end.
Global Instance valid_rnd_odd : Valid_rnd Zrnd_odd.

Lemma Zrnd_odd_plus: forall x y, (x = IZR (Zfloor x)) ->
Z.even (Zfloor x) = true ->
(IZR (Zrnd_odd (x+y)) = x+IZR (Zrnd_odd y))%R.