Common — library colibrilib.fbin — module Special

The special values and the classes

The floats of F.get_special_values by their index (ix neg k is the index of the magnitude k with the sign neg), and the classes of a float.

3077
module Special
3078
use int.Int
3079
use int.Power
3080
use Pow2r
3081
use Format
3082
use Float
3083
use Round
3084
use Impl
3085
3086
function
ix
(neg: bool) (k: int) : int = if neg then -1 - k else k
3087
3088
type
signed
= {
3089
sv_zero
: t;
sv_first_subnormal
: t;
sv_last_subnormal
: t;
3090
sv_first_normal
: t;
sv_last_normal
: t;
sv_infinite
: t }
3091
3092
predicate
at_i
(fm: format) (x: t) (i: int) = x.fmt = fm /\ not is_nan x /\ index x = i
3093
Valid (1.2s) (cvc4)
3094
let
signed_values
(fm: format) (neg: bool) : signed
3095
ensures { at_i fm result.sv_zero (ix neg 0) }
3096
ensures { at_i fm result.sv_first_subnormal (ix neg 1) }
3097
ensures { at_i fm result.sv_last_subnormal (ix neg (binade fm - 1)) }
3098
ensures { at_i fm result.sv_first_normal (ix neg (binade fm)) }
3099
ensures { at_i fm result.sv_last_normal (ix neg (nb_sign fm - 2)) }
3100
ensures { at_i fm result.sv_infinite (ix neg (nb_sign fm - 1)) }
3101
ensures { if neg then is_minus_infinity result.sv_infinite
3102
else is_plus_infinity result.sv_infinite }
3103
= let p = binade_p fm in
3104
let nb = nb_sign_p fm in
3105
let ix (k: int) : int ensures { result = ix neg k } = if neg then -1 - k else k in
3106
{proof…}
3107
binade_ge_2 fm; nb_sign_ge fm;
3108
assert { binade fm < nb_sign fm - 2 by
3109
nb_sign fm = (power 2 fm.eb - 1) * binade fm + 1 /\ 3 <= power 2 fm.eb - 1 };
3110
of_index_range fm (ix 0); of_index_range fm (ix 1);
3111
of_index_range fm (ix (p - 1)); of_index_range fm (ix p);
3112
of_index_range fm (ix (nb - 2)); of_index_range fm (ix (nb - 1));
3113
{qed}
3114
{ sv_zero = of_index_p fm (ix 0);
3115
sv_first_subnormal = of_index_p fm (ix 1);
3116
sv_last_subnormal = of_index_p fm (ix (p - 1));
3117
sv_first_normal = of_index_p fm (ix p);
3118
sv_last_normal = of_index_p fm (ix (nb - 2));
3119
sv_infinite = of_index_p fm (ix (nb - 1)) }
3120
Valid (42ms) (colibri2)
3121
let
is_subnormal_p
(x: t) : bool
3122
ensures { result <-> is_subnormal x }
3123
= match x.value with Finite _ k -> 0 < k && k < binade_p x.fmt | _ -> false end
3124
Valid (35ms) (colibri2)
3125
let
is_normal_p
(x: t) : bool
3126
ensures { result <-> is_normal x }
3127
= match x.value with Finite _ k -> binade_p x.fmt <= k | _ -> false end
3128
end