(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
RequireImport PrimInt63 FloatClass.
(** * Definition of the interface for primitive floating-point arithmetic
This interface provides processor operators for the Binary64 format of the
IEEE 754-2008 standard. *)
(** ** Type definition for the co-domain of [compare] *)
Variant float_comparison : Set := FEq | FLt | FGt | FNotComparable.
Register float_comparison as kernel.ind_f_cmp.
Register float_class as kernel.ind_f_class.
(** ** The main type *) (** [float]: primitive type for Binary64 floating-point numbers. *)
Primitive float := #float64_type.
Register float as num.float.type.
(** For the record: this is the IEEE754 equality
(eqb nan nan = false and eqb +0 -0 = true) *)
Primitive eqb := #float64_eq.
Primitive ltb := #float64_lt.
Primitive leb := #float64_le.
Primitive compare := #float64_compare.
(** Boolean Leibniz equality *) Module Leibniz.
Primitive eqb := #float64_equal.
Register eqb as num.float.leibniz.eqb. End Leibniz.
Primitive mul := #float64_mul.
Primitive add := #float64_add.
Primitive sub := #float64_sub.
Primitive div := #float64_div.
ModuleImport PrimFloatNotationsInternalB. Notation"- x" := (opp x) : float_scope. Notation"x =? y" := (eqb x y) (at level 70, no associativity) : float_scope. Notation"x y" := (ltb x y) (at level 70, no associativity) : float_scope. Notation"x <=? y" := (leb x y) (at level 70, no associativity) : float_scope. Notation"x ?= y" := (compare x y) (at level 70, no associativity) : float_scope. Notation"x * y" := (mul x y) : float_scope. Notation"x + y" := (add x y) : float_scope. Notation"x - y" := (sub x y) : float_scope. Notation"x / y" := (div x y) : float_scope. End PrimFloatNotationsInternalB.
(** ** Conversions *)
(** [of_uint63]: convert a primitive unsigned integer into a float value.
The value is rounded if need be. *)
Primitive of_uint63 := #float64_of_uint63.
(** Specification of [normfr_mantissa]: - If the input is a float value with an absolute value inside $[0.5, 1.)$#[0.5, 1.)#; - Then return its mantissa as a primitive integer. The mantissa will be a 53-bit integer with its most significant bit set to 1; - Else return zero.
The sign bit is always ignored. *)
Primitive normfr_mantissa := #float64_normfr_mantissa.
(** ** Exponent manipulation functions *) (** [frshiftexp]: convert a float to fractional part in $[0.5, 1.)$#[0.5, 1.)#
and integer part. *)
Primitive frshiftexp := #float64_frshiftexp.
(** [ldshiftexp]: multiply a float by an integral power of 2. *)
Primitive ldshiftexp := #float64_ldshiftexp.
(** ** Predecesor/Successor functions *)
(** [next_up]: return the next float towards positive infinity. *)
Primitive next_up := #float64_next_up.
(** [next_down]: return the next float towards negative infinity. *)
Primitive next_down := #float64_next_down.
(** ** Special values (needed for pretty-printing) *) Definition infinity := Evalcompute in div (of_uint63 1) (of_uint63 0). Definition neg_infinity := Evalcompute in opp infinity. Definition nan := Evalcompute in div (of_uint63 0) (of_uint63 0).
Register infinity as num.float.infinity.
Register neg_infinity as num.float.neg_infinity.
Register nan as num.float.nan.
(** ** Other special values *) Definition one := Evalcompute in (of_uint63 1). Definition zero := Evalcompute in (of_uint63 0). Definition neg_zero := Evalcompute in (-zero)%float. Definition two := Evalcompute in (of_uint63 2).
(** ** Predicates and helper functions *) Definition is_nan f := negb (f =? f)%float.
Definition is_zero f := (f =? zero)%float. (* note: 0 =? -0 with floats *)
Definition is_infinity f := (abs f =? infinity)%float.
(** [get_sign]: return [true] for [-] sign, [false] for [+] sign. *) Definition get_sign f := let f := if is_zero f then (one / f)%float else f in
(f <? zero)%float.
ModuleExport PrimFloatNotations. LocalOpenScope float_scope. Export PrimFloatNotationsInternalA. Export PrimFloatNotationsInternalB. End PrimFloatNotations.
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 und die Messung sind noch experimentell.