IEEE_854_values
[b,p:above(1),
E_max:integer,
E_min:{i:integer|E_max>i}]: THEORY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This file defines the set of values that must be represented in each % supported precision of an instance of IEEE-854 % % Author: % Paul S. Miner | email: p.s.miner@larc.nasa.gov % 1 South Wright St. / MS 130 | fax: (757) 864-4234 % NASA Langley Research Center | phone: (757) 864-6201 % Hampton, Virginia 23681 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BEGIN
IMPORTING sum_hack, %for use until we have good summation library
sum_lemmas[b], % these are more specialized % ints@mod_, %% note _ to avoid prelude version
enumerated_type_defs
Exponent: type = {i:int| E_min <= i & i <= E_max}
digits: type = [below(p)->below(b)]
fp_num: datatype begin
finite(sign:sign_rep,Exp:Exponent,d:digits):finite?
infinite(i_sign:sign_rep): infinite?
NaN(status:NaN_type, data:NaN_data): NaN? end fp_num
% A mapping from finite floating point numbers to real numbers % This corresponds to the interpretation given in the standard % section 3.1
fin : var (finite?)
value_digit(d:digits)(n:nat):nonneg_real = if n<p then d(n)*b^(-n) else 0 endif
value(fin): real =
(-1) ^ sign(fin) * b ^ Exp(fin) * Sum(p, value_digit(d(fin)))
% Predicate testing whether an fp_num is 0
zero?(fp:fp_num):bool = if finite?(fp) then value(fp)=0 elsefalseendif
shift_left((d: digits)): digits = LAMBDA (i: below(p)): IF (i + 1 = p) THEN 0 ELSE d(i + 1) ENDIF
% Function normalize takes a finite and returns the finite of % equivalent value with the smallest possible exponent.
normalize(fin:(finite?)): recursive (finite?) = IF Exp(fin) = E_min or d(fin)(0) /= 0 then
fin ELSE
normalize(finite(sign(fin),Exp(fin)-1,shift_left(d(fin)))) ENDIF measurelambda (fin:(finite?)): Exp(fin) - E_min
% Predicate testing whether an fp_num is subnormal: % Section 2 of the standard defines a subnormal (denormal in IEEE-754) % number as a nonzero finite number whose exponent is the precision's % minimum and whose leading significant digit is zero.
subnormal?(fp: fp_num): bool = IF finite?(fp) THEN not zero?(fp)
& Exp(normalize(fp)) = E_min
& d(normalize(fp))(0) = 0 ELSEFALSE ENDIF
% Predicate testing whether an fp_num is normal: % Section 2 of the standard defines a normal number as % a nonzero finite number that is not subnormal
normal?((fp: fp_num)): bool = IF finite?(fp) THEN d(normalize(fp))(0) > 0 ELSEFALSEENDIF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Some definitions and theorems to help illustrate the correctness % of the definition of value.
% Maximum and Minimum representable values
max_significand:digits =
(lambda (i:below(p)): b-1)
min_significand: digits =
(LAMBDA (i: below(p)): IF i < p - 1 THEN 0 ELSE 1 ENDIF)
d_zero: digits = LAMBDA (i: below(p)): 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
fp,fp1,fp2: var fp_num
% reverse the sign of a floating point number
toggle_sign(fp): fp_num
= cases fp of
finite(s,e,d): finite(1-s,e,d),
infinite(s): infinite(1-s),
NaN(sig,data): fp endcases
%%%%%%%%% % % The next two declarations are here for importing purposes.
% A dummy fp_num to be used as a place holder. Any definition that % returns holder is not yet finished.
holder:fp_num
% An undefined NaN for functions to return when the invalid exception % should be raised. This serves as a placeholder until this specification % accounts for exceptions. %
invalid: (NaN?) = NaN(quiet,invalid_data)
END IEEE_854_values
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.