library colibrilib.flocq — module RoundThe rounding of the reals to the floats of prec bits of significand and least exponent emin, with an unbounded exponent above: Flocq's round radix2 (FLT_exp emin prec) (Flocq.Core.Generic_fmt), for the modes of IEEE 754.
This theory is realized in Rocq in common/rocq/flocq/Round.v: the functions are defined by Flocq's round, and the axioms are proved there from Flocq's lemmas (round_DN_pt, round_UP_pt, round_ZR_DN, round_ZR_UP, round_NE_pt, round_NA_pt). Build: common/rocq/build.sh. It uses only the theories of the standard library, so the realization rests only on the realizations of Why3 and on Flocq.
colibrilib.fbin_ieee proves that the rounding of fbin.mlw is this one.
theory Round17use int.Int18use int.Power19use real.RealInfix20use real.FromInt21use real.Abs22
2^e for every integer e (Flocq's bpow radix2 e)
function pow2 (e: int) : real =25if 0 <= e then from_int (power 2 e) else 1.0 /. from_int (power 2 (-e))26
The floats of the format (Flocq's FLT_format, equivalent to generic_format radix2 (FLT_exp emin prec))
predicate generic (prec emin: int) (x: real) =30exists m e. emin <= e /\ - power 2 prec < m < power 2 prec /\31x = from_int m *. pow2 e32
x has a representation with an even significand (Flocq's NE_prop gives the canonical one)
predicate even_repr (prec emin: int) (x: real) =36exists m e. emin <= e /\ - power 2 prec < m < power 2 prec /\37x = from_int m *. pow2 e /\ exists q. m = 2 * q38
f is a float nearest to r (Flocq's Rnd_N_pt)
predicate nearest (prec emin: int) (r f: real) =41generic prec emin f /\42forall g. generic prec emin g -> abs (f -. r) <=. abs (g -. r)43
The roundings: toward minus infinity (Zfloor), toward plus infinity (Zceil), toward zero (Ztrunc), to nearest ties to even (ZnearestE), to nearest ties away from zero (ZnearestA)
function rnd_dn (prec emin: int) (r: real) : real48function rnd_up (prec emin: int) (r: real) : real49function rnd_zr (prec emin: int) (r: real) : real50function rnd_ne (prec emin: int) (r: real) : real51function rnd_na (prec emin: int) (r: real) : real52
Flocq's round_DN_pt: the greatest float below
axiom rnd_dn_spec: forall prec emin r. 0 < prec ->55generic prec emin (rnd_dn prec emin r) /\ rnd_dn prec emin r <=. r /\56forall g. generic prec emin g -> g <=. r -> g <=. rnd_dn prec emin r57
Flocq's round_UP_pt: the least float above
axiom rnd_up_spec: forall prec emin r. 0 < prec ->60generic prec emin (rnd_up prec emin r) /\ r <=. rnd_up prec emin r /\61forall g. generic prec emin g -> r <=. g -> rnd_up prec emin r <=. g62
Flocq's round_ZR_DN and round_ZR_UP
axiom rnd_zr_spec: forall prec emin r. 0 < prec ->65rnd_zr prec emin r =66if 0.0 <=. r then rnd_dn prec emin r else rnd_up prec emin r67
Flocq's round_NE_pt: a nearest float, the even one on a tie
axiom rnd_ne_spec: forall prec emin r. 1 < prec ->70nearest prec emin r (rnd_ne prec emin r) /\71forall g. nearest prec emin r g -> g <> rnd_ne prec emin r ->72even_repr prec emin (rnd_ne prec emin r)73
Flocq's round_NA_pt: a nearest float, the larger in magnitude on a tie
axiom rnd_na_spec: forall prec emin r. 0 < prec ->77nearest prec emin r (rnd_na prec emin r) /\78forall g. nearest prec emin r g -> abs g <=. abs (rnd_na prec emin r)79end80