(** IEEE-754 roundings: up, down and to zero *)

Global Instance valid_rnd_DN : Valid_rnd Zfloor.Global Instance valid_rnd_UP : Valid_rnd Zceil.Global Instance valid_rnd_ZR : Valid_rnd Ztrunc.Global Instance valid_rnd_AW : Valid_rnd Zaway.

(* Specifications: *)
Theorem round_DN_or_UP : forall x, round rnd x = round Zfloor x \/ round rnd x = round Zceil x.
Theorem round_ZR_or_AW : forall x, round rnd x = round Ztrunc x \/ round rnd x = round Zaway x.
Theorem round_le : forall x y, (x <= y)%R -> (round rnd x <= round rnd y)%R.
Theorem round_ge_generic : forall x y, generic_format x -> (x <= y)%R -> (x <= round rnd y)%R.
Theorem round_le_generic : forall x y, generic_format y -> (x <= y)%R -> (round rnd x <= y)%R.
Theorem round_abs_abs : forall P : R -> R -> Prop, ( forall rnd (Hr : Valid_rnd rnd) x, (0 <= x)%R -> P x (round rnd x) ) -> forall rnd {Hr : Valid_rnd rnd} x, P (Rabs x) (Rabs (round rnd x)).
Theorem round_bounded_large : forall rnd {Hr : Valid_rnd rnd} x ex, (fexp ex < ex)%Z -> (bpow (ex - 1) <= Rabs x < bpow ex)%R -> (bpow (ex - 1) <= Rabs (round rnd x) <= bpow ex)%R.
Theorem exp_small_round_0 : forall rnd {Hr : Valid_rnd rnd} x ex, (bpow (ex - 1) <= Rabs x < bpow ex)%R -> round rnd x = 0%R -> (ex <= fexp ex)%Z .
Theorem abs_round_ge_generic : forall x y, generic_format x -> (x <= Rabs y)%R -> (x <= Rabs (round rnd y))%R.
Theorem abs_round_le_generic : forall x y, generic_format y -> (Rabs x <= y)%R -> (Rabs (round rnd x) <= y)%R.
Theorem round_DN_opp : forall x, round Zfloor (-x) = (- round Zceil x)%R.
Theorem round_UP_opp : forall x, round Zceil (-x) = (- round Zfloor x)%R.
Theorem round_ZR_opp : forall x, round Ztrunc (- x) = Ropp (round Ztrunc x).
Theorem round_ZR_abs : forall x, round Ztrunc (Rabs x) = Rabs (round Ztrunc x).
Theorem round_AW_opp : forall x, round Zaway (- x) = Ropp (round Zaway x).
Theorem round_AW_abs : forall x, round Zaway (Rabs x) = Rabs (round Zaway x).
Theorem round_ZR_pos : forall x, (0 <= x)%R -> round Ztrunc x = round Zfloor x.
Theorem round_ZR_neg : forall x, (x <= 0)%R -> round Ztrunc x = round Zceil x.
Theorem round_AW_pos : forall x, (0 <= x)%R -> round Zaway x = round Zceil x.
Theorem round_AW_neg : forall x, (x <= 0)%R -> round Zaway x = round Zfloor x.
Theorem generic_format_round : forall rnd { Hr : Valid_rnd rnd } x, generic_format (round rnd x).
Theorem round_DN_pt : forall x, Rnd_DN_pt generic_format x (round Zfloor x).
Theorem generic_format_satisfies_any : satisfies_any generic_format.
Theorem round_UP_pt : forall x, Rnd_UP_pt generic_format x (round Zceil x).
Theorem round_ZR_pt : forall x, Rnd_ZR_pt generic_format x (round Ztrunc x).
Theorem round_DN_small_pos : forall x ex, (bpow (ex - 1) <= x < bpow ex)%R -> (ex <= fexp ex)%Z -> round Zfloor x = 0%R.
Theorem round_DN_UP_lt : forall x, ~ generic_format x -> (round Zfloor x < x < round Zceil x)%R.
Theorem round_UP_small_pos : forall x ex, (bpow (ex - 1) <= x < bpow ex)%R -> (ex <= fexp ex)%Z -> round Zceil x = (bpow (fexp ex)).
Theorem generic_format_EM : forall x, generic_format x \/ ~generic_format x.
Theorem round_large_pos_ge_pow : forall x e, (0 < round rnd x)%R -> (bpow e <= x)%R -> (bpow e <= round rnd x)%R.
Theorem ln_beta_round_ZR : forall x, (round Ztrunc x <> 0)%R -> (ln_beta beta (round Ztrunc x) = ln_beta beta x :> Z).
Theorem ln_beta_round : forall rnd {Hrnd : Valid_rnd rnd} x, (round rnd x <> 0)%R -> (ln_beta beta (round rnd x) = ln_beta beta x :> Z) \/ Rabs (round rnd x) = bpow (Zmax (ln_beta beta x) (fexp (ln_beta beta x))).
Theorem ln_beta_DN : forall x, (0 < round Zfloor x)%R -> (ln_beta beta (round Zfloor x) = ln_beta beta x :> Z).
Theorem canonic_exp_DN : forall x, (0 < round Zfloor x)%R -> canonic_exp (round Zfloor x) = canonic_exp x.
Theorem scaled_mantissa_DN : forall x, (0 < round Zfloor x)%R -> scaled_mantissa (round Zfloor x) = Z2R (Zfloor (scaled_mantissa x)).
Theorem generic_N_pt_DN_or_UP : forall x f, Rnd_N_pt generic_format x f -> f = round Zfloor x \/ f = round Zceil x.