(** Conversion from an integer.  Round to nearest. *)
Definition BofZ (n: Z) : binary_float :=
binary_normalize prec emax prec_gt_0_ Hmax mode_NE n 0 false.

(* Specifications: *)
Theorem BofZ_correct:
forall n,
if Rlt_bool (Rabs (round radix2 fexp (round_mode mode_NE) (Z2R n))) (bpow radix2 emax)
then
B2R prec emax (BofZ n) = round radix2 fexp (round_mode mode_NE) (Z2R n) /\
is_finite _ _ (BofZ n) = true /\
Bsign prec emax (BofZ n) = Z.ltb n 0
else
B2FF prec emax (BofZ n) = binary_overflow prec emax mode_NE (Z.ltb n 0).
Theorem BofZ_finite:
forall n,
Z.abs n <= 2^emax - 2^(emax-prec) ->
B2R _ _ (BofZ n) = round radix2 fexp (round_mode mode_NE) (Z2R n)
/\ is_finite _ _ (BofZ n) = true
/\ Bsign _ _ (BofZ n) = Z.ltb n 0%Z.
Theorem BofZ_representable:
forall n,
integer_representable n ->
B2R _ _ (BofZ n) = Z2R n
/\ is_finite _ _ (BofZ n) = true
/\ Bsign _ _ (BofZ n) = (n <? 0).
Theorem BofZ_exact:
forall n,
-2^prec <= n <= 2^prec ->
B2R _ _ (BofZ n) = Z2R n
/\ is_finite _ _ (BofZ n) = true
/\ Bsign _ _ (BofZ n) = Z.ltb n 0%Z.
Lemma BofZ_finite_pos0:
forall n,
Z.abs n <= 2^emax - 2^(emax-prec) -> is_finite_pos0 (BofZ n) = true.
Lemma BofZ_finite_equal:
forall x y,
Z.abs x <= 2^emax - 2^(emax-prec) ->
Z.abs y <= 2^emax - 2^(emax-prec) ->
B2R _ _ (BofZ x) = B2R _ _ (BofZ y) ->
BofZ x = BofZ y.