(** Relates location and rounding to nearest. *)

Definition round_N (p : bool) l :=
  match l with
  | loc_Exact => false
  | loc_Inexact Lt => false
  | loc_Inexact Eq => p
  | loc_Inexact Gt => true
  end.

(* Specifications: *)
Theorem inbetween_int_N : forall choice x m l, inbetween_int m x l -> Znearest choice x = cond_incr (round_N (choice m) l) m.
Theorem inbetween_int_N_sign : forall choice x m l, inbetween_int m (Rabs x) l -> Znearest choice x = cond_Zopp (Rlt_bool x 0) (cond_incr (round_N (if Rlt_bool x 0 then negb (choice (-(m + 1))%Z) else choice m) l) m).
Theorem inbetween_int_NE : forall x m l, inbetween_int m x l -> ZnearestE x = cond_incr (round_N (negb (Zeven m)) l) m.
Theorem inbetween_float_NE : forall x m l, let e := canonic_exp beta fexp x in inbetween_float beta m e x l -> round beta fexp ZnearestE x = F2R (Float beta (cond_incr (round_N (negb (Zeven m)) l) m) e).
Theorem inbetween_int_NE_sign : forall x m l, inbetween_int m (Rabs x) l -> ZnearestE x = cond_Zopp (Rlt_bool x 0) (cond_incr (round_N (negb (Zeven m)) l) m).
Theorem inbetween_float_NE_sign : forall x m l, let e := canonic_exp beta fexp x in inbetween_float beta m e (Rabs x) l -> round beta fexp ZnearestE x = F2R (Float beta (cond_Zopp (Rlt_bool x 0) (cond_incr (round_N (negb (Zeven m)) l) m)) e).
Theorem inbetween_int_NA : forall x m l, inbetween_int m x l -> ZnearestA x = cond_incr (round_N (Zle_bool 0 m) l) m.
Theorem inbetween_float_NA : forall x m l, let e := canonic_exp beta fexp x in inbetween_float beta m e x l -> round beta fexp ZnearestA x = F2R (Float beta (cond_incr (round_N (Zle_bool 0 m) l) m) e).
Theorem inbetween_int_NA_sign : forall x m l, inbetween_int m (Rabs x) l -> ZnearestA x = cond_Zopp (Rlt_bool x 0) (cond_incr (round_N true l) m).