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.

Lemma zero_ext_range':
forall n x, 0 <= n < Int.zwordsize ->
0 <= Int.unsigned (Int.zero_ext n x) <= two_p n - 1.