Definition general_offloat (prec emax : Z)
(f:  Fappli_IEEE.binary_float prec emax) : option Z :=
match f with
| Fappli_IEEE.B754_zero _ => Some 0
| Fappli_IEEE.B754_infinity _ => None
| Fappli_IEEE.B754_nan _ _ => None
| Fappli_IEEE.B754_finite s m 0 _ => Some (Fcore_Zaux.cond_Zopp s (Z.pos m))
| Fappli_IEEE.B754_finite s m (Z.pos e) _ =>
Some (Fcore_Zaux.cond_Zopp s (Z.pos m) * Z.pow_pos 2 e)
| Fappli_IEEE.B754_finite s m (Z.neg e) _ =>
Some (Fcore_Zaux.cond_Zopp s (Z.pos m / Z.pow_pos 2 e))
end.
Definition general_float_to_int (prec emax : Z) (lo hi: Z) (f: Fappli_IEEE.binary_float prec emax) : option int :=
option_map Int.repr
(Fappli_IEEE_extra.ZofB_range prec emax f lo hi).
Goal Zoffloat = general_offloat 53 1024.
reflexivity.
Qed.
Goal Zofsingle = general_offloat 24 128.
reflexivity.
Qed.
Goal Float.to_int = general_float_to_int 53 1024 Int.min_signed Int.max_signed.
reflexivity.
Qed.
Goal Float.to_intu = general_float_to_int 53 1024 0 Int.max_unsigned.
reflexivity.
Qed.
Goal Float32.to_int = general_float_to_int 24 128 Int.min_signed Int.max_signed.
reflexivity.
Qed.
Goal Float32.to_intu = general_float_to_int 24 128 0 Int.max_unsigned.
reflexivity.
Qed.

(* Specifications: *)
Lemma general_float_to_int_ok:
forall prec emax lo hi f z,
general_offloat prec emax f = Some z ->
lo <= z <= hi ->
general_float_to_int prec emax lo hi f = Some (Int.repr z).
Lemma float_to_int_ok:
forall f z,
Zoffloat f = Some z ->
Int.min_signed <= z <= Int.max_signed ->
Float.to_int f = Some (Int.repr z).
Lemma float_to_intu_ok:
forall f z,
Zoffloat f = Some z ->
0 <= z <= Int.max_unsigned ->
Float.to_intu f = Some (Int.repr z).
Lemma single_to_int_ok:
forall f z,
Zofsingle f = Some z ->
Int.min_signed <= z <= Int.max_signed ->
Float32.to_int f = Some (Int.repr z).
Lemma single_to_intu_ok:
forall f z,
Zofsingle f = Some z ->
0 <= z <= Int.max_unsigned ->
Float32.to_intu f = Some (Int.repr z).
(* not necessary if rewrite denote_tc_assert_andp *)
(* Lemma denote_tc_assert_andp_e: forall a b rho, denote_tc_assert Delta (tc_andp a b) rho -> denote_tc_assert Delta a rho /\ denote_tc_assert Delta b rho. *)
Lemma andb_zleb:
forall i j k : Z,  i <= j <= k ->
(i <=? j) && (j <=? k) = true.
Lemma sign_ext_range':
forall n x, 0 < n < Int.zwordsize ->
- two_p (n - 1) <= Int.signed (Int.sign_ext n x) <= two_p (n - 1) -1.
Lemma zero_ext_range':
forall n x, 0 <= n < Int.zwordsize ->
0 <= Int.unsigned (Int.zero_ext n x) <= two_p n - 1.
Lemma int64_eq_e: forall i, Int64.eq i Int64.zero = true -> i=Int64.zero.
Lemma long_int_zero_lem:
forall i, Int64.eq (Int64.repr (Int64.unsigned i)) Int64.zero = true ->
Int.repr (Int64.unsigned i) = Int.zero.
Lemma typecheck_cast_sound:
forall {CS: compspecs} Delta rho m e t,
typecheck_environ Delta rho ->
(denote_tc_assert (typecheck_expr Delta e) rho m ->
tc_val (typeof e) (eval_expr e rho))  ->
denote_tc_assert (typecheck_expr Delta (Ecast e t)) rho m ->
tc_val (typeof (Ecast e t)) (eval_expr (Ecast e t) rho).