Fixpoint Pos_is_pow2 (p : positive) : bool :=
match p with
| (p'~1)%positive => false
| (p'~0)%positive => Pos_is_pow2 p'
| 1%positive      => true
end.
(** ** Power of two closed upper bound [q <= 2^z] *)
Definition Qbound_le_ZExp2 (q : Q) : Z :=
match Qnum q with
(* The -1000 is a compromise between a tight Archimedian and avoiding too large numbers *)
| Z0 => -1000
| Zneg p => 0
| Zpos p => (Z.pos (Pos_log2ceil_plus1 p) - Z.pos (Pos_log2floor_plus1 (Qden q)))%Z
end.

Lemma Qbound_le_ZExp2_spec : forall (q : Q),
(q <= 2^(Qbound_le_ZExp2 q))%Q.