(** Given a base [base], a mantissa [m] and an exponent [e], the following function computes the FP number closest to [m * base ^ e], using round to odd, ties break to even. The algorithm is naive, computing [base ^ |e|] exactly before doing a multiplication or division with [m].  However, we treat specially very large or very small values of [e], when the result is known to be [+infinity] or [0.0] respectively. *)
Definition Bparse (base: positive) (m: positive) (e: Z): binary_float :=
match e with
| Z0 =>
BofZ (Zpos m)
| Zpos p =>
if e * Z.log2 (Zpos base) <? emax
then BofZ (Zpos m * Zpos (pos_pow base p))
else B754_infinity _ _ false
| Zneg p =>
if e * Z.log2 (Zpos base) + Z.log2_up (Zpos m) <? emin
then B754_zero _ _ false
else FF2B prec emax _ (proj1 (Bdiv_correct_aux prec emax prec_gt_0_ Hmax mode_NE
false m Z0 false (pos_pow base p) Z0))
end.
(** Properties of [Z.log2] and [Z.log2_up]. *)

Lemma bpow_log_pos:
forall (base: radix) n,
0 < n ->
(bpow radix2 (n * Z.log2 base)%Z <= bpow base n)%R.