(****************************************************************************  IEEE754  :  ClosestPlus  Laurent Thery, Sylvie Boldo  ******************************************************************************)
Require Export FroundPlus.
Require Export ClosestProp.
Section ClosestP.
Variable b : Fbound.
Variable radix : Z.
Variable precision : nat.
Let FtoRradix := FtoR radix.
Local Coercion FtoRradix : float >-> R.
Hypothesis radixMoreThanOne : (1 < radix)%Z.
Let radixMoreThanZERO := Zlt_1_O _ (Zlt_le_weak _ _ radixMoreThanOne).
Hint Resolve radixMoreThanZERO: zarith.
Hypothesis precisionGreaterThanOne : 1 < precision.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix precision.

Theorem errorBoundedPlusLe :
forall p q pq : float,
Fbounded b p ->
Fbounded b q ->
(Fexp p <= Fexp q)%Z ->
Closest b radix (p + q) pq ->
exists error : float,
error = Rabs (p + q - pq) :>R /\
Fbounded b error /\ Fexp error = Zmin (Fexp p) (Fexp q).