(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*          Jacques-Henri Jourdan, INRIA Paris-Rocquencourt            *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 2 of the License, or  *)
(*  (at your option) any later version.  This file is also distributed *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Formalization of floating-point numbers, using the Flocq library. *)
(*From Flocq*)
Require Archi.
Close Scope R_scope.
Open Scope Z_scope.
Definition float := binary64. (**r the type of IEE754 double-precision FP numbers *)
Definition float32 := binary32. (**r the type of IEE754 single-precision FP numbers *)
(** Boolean-valued comparisons *)
Definition cmp_of_comparison (c: comparison) (x: option Datatypes.comparison) : bool :=
match c with
| Ceq =>
match x with Some Eq => true | _ => false end
| Cne =>
match x with Some Eq => false | _ => true end
| Clt =>
match x with Some Lt => true | _ => false end
| Cle =>
match x with Some(Lt|Eq) => true | _ => false end
| Cgt =>
match x with Some Gt => true | _ => false end
| Cge =>
match x with Some(Gt|Eq) => true | _ => false end
end.
Definition ordered_of_comparison (x: option Datatypes.comparison) : bool :=
match x with None => false | Some _ => true end.
(** Normalization of NaN payloads *)
(** Transform a Nan payload to a quiet Nan payload. *)
Definition quiet_nan_64_payload (p: positive) :=
Z.to_pos (P_mod_two_p (Pos.lor p ((iter_nat xO 51 1%positive))) 52%nat).

Lemma quiet_nan_64_proof: forall p, nan_pl 53 (quiet_nan_64_payload p) = true.