Common — library colibrilib.generic_divrem_rewrite — module Round

Rounding of an integer plus a fraction (for the clones of Gen)

301
module Round
302
use int.Int
303
use real.RealInfix
304
use real.FromInt
305
use real.Truncate as Truncate
306
Valid (23ms) (colibri2)
307
let lemma
floor_shift
(d:int) (f:real)
308
requires { 0. <=. f <. 1. }
309
ensures { Truncate.floor (from_int d +. f) = d }
310
= let z = Truncate.floor (from_int d +. f) in
311
assert { from_int z <=. from_int d +. f <. from_int (z + 1) };
312
assert { from_int z <. from_int (d + 1) };
313
assert { from_int d <. from_int (z + 1) }
314
Valid (24ms) (colibri2)
315
let lemma
ceil_shift
(d:int) (f:real)
316
requires { -. 1. <. f <=. 0. }
317
ensures { Truncate.ceil (from_int d +. f) = d }
318
= let z = Truncate.ceil (from_int d +. f) in
319
assert { from_int (z - 1) <. from_int d +. f <=. from_int z };
320
assert { from_int (z - 1) <. from_int d };
321
assert { from_int (d - 1) <. from_int z }
322
end