Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
why3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Fitinghoff
why3
Commits
58a3584f
Commit
58a3584f
authored
6 years ago
by
Claude Marché
Browse files
Options
Downloads
Patches
Plain Diff
Stdlib/floats: allow the use of basic float operations in programs
parent
442bffc9
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/in_progress/my_cosine.mlw
+1
-1
1 addition, 1 deletion
examples/in_progress/my_cosine.mlw
stdlib/ieee_float.mlw
+37
-33
37 additions, 33 deletions
stdlib/ieee_float.mlw
stdlib/mach/float.mlw
+3
-3
3 additions, 3 deletions
stdlib/mach/float.mlw
with
41 additions
and
37 deletions
examples/in_progress/my_cosine.mlw
+
1
−
1
View file @
58a3584f
...
@@ -84,6 +84,6 @@ module Combined
...
@@ -84,6 +84,6 @@ module Combined
assert {
assert {
Abs.abs (1.0 -. (t'real x) *. (t'real x) *. 0.5 -. cos (t'real x)) <=. 0x1p-24
Abs.abs (1.0 -. (t'real x) *. (t'real x) *. 0.5 -. cos (t'real x)) <=. 0x1p-24
};
};
sub (1.0:t) (
mul (
mul x x) (0.5:t))
safe_
sub (1.0:t) (
safe_mul (safe_
mul x x) (0.5:t))
end
end
This diff is collapsed.
Click to expand it.
stdlib/ieee_float.mlw
+
37
−
33
View file @
58a3584f
...
@@ -60,7 +60,7 @@ module GenericFloat
...
@@ -60,7 +60,7 @@ module GenericFloat
(** {3 Constructors and Constants} *)
(** {3 Constructors and Constants} *)
constant zeroF : t (** +0.0 *)
val
constant zeroF : t (** +0.0 *)
(* exp_bias = 2^(sb - 1) - 1 *)
(* exp_bias = 2^(sb - 1) - 1 *)
(* max_finite_exp = 2^sb - 2 - exp_bias = exp_bias *)
(* max_finite_exp = 2^sb - 2 - exp_bias = exp_bias *)
(* max_significand = (2^eb + 2^eb - 1) * 2^(1-eb) *)
(* max_significand = (2^eb + 2^eb - 1) * 2^(1-eb) *)
...
@@ -70,25 +70,25 @@ module GenericFloat
...
@@ -70,25 +70,25 @@ module GenericFloat
(** {3 Operators} *)
(** {3 Operators} *)
function add mode t t : t
val
function add mode t t : t
function sub mode t t : t
val
function sub mode t t : t
function mul mode t t : t
val
function mul mode t t : t
function div mode t t : t
val
function div mode t t : t
(** The four basic operations, rounded in the given mode *)
(** The four basic operations, rounded in the given mode *)
function abs t : t (** Absolute value *)
val
function abs t : t (** Absolute value *)
function neg t : t (** Opposite *)
val
function neg t : t (** Opposite *)
function fma mode t t t : t (** Fused multiply-add: x * y + z *)
val
function fma mode t t t : t (** Fused multiply-add: x * y + z *)
function sqrt mode t : t (** Square root *)
val
function sqrt mode t : t (** Square root *)
function (.-_) (x:t) : t = neg x
let
function (.-_) (x:t) : t = neg x
function (.+) (x y:t) : t = add RNE x y
let
function (.+) (x y:t) : t = add RNE x y
function (.-) (x y:t) : t = sub RNE x y
let
function (.-) (x y:t) : t = sub RNE x y
function (.*) (x y:t) : t = mul RNE x y
let
function (.*) (x y:t) : t = mul RNE x y
function (./) (x y:t) : t = div RNE x y
let
function (./) (x y:t) : t = div RNE x y
(** Notations for operations in the default mode RNE *)
(** Notations for operations in the default mode RNE *)
function roundToIntegral mode t : t
val
function roundToIntegral mode t : t
(** Rounding to an integer *)
(** Rounding to an integer *)
function min t t : t
function min t t : t
...
@@ -100,22 +100,26 @@ module GenericFloat
...
@@ -100,22 +100,26 @@ module GenericFloat
2) if either argument is NaN then the other argument is returned
2) if either argument is NaN then the other argument is returned
Due to the unclear status of min and max in IEEE norm, we
intentionally not provide these function as "val"s to be used in
programs
*)
*)
(** {3 Comparisons} *)
(** {3 Comparisons} *)
predicate le t t
val
predicate le t t
predicate lt t t
val
predicate lt t t
predicate ge (x:t) (y:t) = le y x
let
predicate ge (x:t) (y:t) = le y x
predicate gt (x:t) (y:t) = lt y x
let
predicate gt (x:t) (y:t) = lt y x
predicate eq t t
val
predicate eq t t
(** equality on floats, different from = since not (eq NaN NaN) *)
(** equality on floats, different from = since not (eq NaN NaN) *)
predicate (.<=) (x:t) (y:t) = le x y
let
predicate (.<=) (x:t) (y:t) = le x y
predicate (.<) (x:t) (y:t) = lt x y
let
predicate (.<) (x:t) (y:t) = lt x y
predicate (.>=) (x:t) (y:t) = ge x y
let
predicate (.>=) (x:t) (y:t) = ge x y
predicate (.>) (x:t) (y:t) = gt x y
let
predicate (.>) (x:t) (y:t) = gt x y
predicate (.=) (x:t) (y:t) = eq x y
let
predicate (.=) (x:t) (y:t) = eq x y
(** Notations *)
(** Notations *)
...
@@ -798,15 +802,15 @@ module Float_BV_Converter
...
@@ -798,15 +802,15 @@ module Float_BV_Converter
(* with unsigned int as bitvector *)
(* with unsigned int as bitvector *)
type t (* float *)
type t (* float *)
function of_ubv8 mode BV8.t : t
val
function of_ubv8 mode BV8.t : t
function of_ubv16 mode BV16.t : t
val
function of_ubv16 mode BV16.t : t
function of_ubv32 mode BV32.t : t
val
function of_ubv32 mode BV32.t : t
function of_ubv64 mode BV64.t : t
val
function of_ubv64 mode BV64.t : t
function to_ubv8 mode t : BV8.t
val
function to_ubv8 mode t : BV8.t
function to_ubv16 mode t : BV16.t
val
function to_ubv16 mode t : BV16.t
function to_ubv32 mode t : BV32.t
val
function to_ubv32 mode t : BV32.t
function to_ubv64 mode t : BV64.t
val
function to_ubv64 mode t : BV64.t
use real.RealInfix
use real.RealInfix
use real.FromInt as FromInt
use real.FromInt as FromInt
...
...
This diff is collapsed.
Click to expand it.
stdlib/mach/float.mlw
+
3
−
3
View file @
58a3584f
...
@@ -16,7 +16,7 @@ module Single
...
@@ -16,7 +16,7 @@ module Single
predicate add_post_real (x:t) (y:t) (r:t) =
predicate add_post_real (x:t) (y:t) (r:t) =
t'real r = round RNE (t'real x +. t'real y)
t'real r = round RNE (t'real x +. t'real y)
val add (x y: t) : t
val
safe_
add (x y: t) : t
requires { [@expl:floating-point overflow]
requires { [@expl:floating-point overflow]
add_pre_ieee x y \/ add_pre_real x y }
add_pre_ieee x y \/ add_pre_real x y }
ensures { add_post_ieee x y result /\ add_post_real x y result }
ensures { add_post_ieee x y result /\ add_post_real x y result }
...
@@ -33,7 +33,7 @@ module Single
...
@@ -33,7 +33,7 @@ module Single
predicate sub_post_real (x:t) (y:t) (r:t) =
predicate sub_post_real (x:t) (y:t) (r:t) =
t'real r = round RNE (t'real x -. t'real y)
t'real r = round RNE (t'real x -. t'real y)
val sub (x y: t) : t
val
safe_
sub (x y: t) : t
requires { [@expl:floating-point overflow]
requires { [@expl:floating-point overflow]
sub_pre_ieee x y \/ sub_pre_real x y }
sub_pre_ieee x y \/ sub_pre_real x y }
ensures { sub_post_ieee x y result /\ sub_post_real x y result }
ensures { sub_post_ieee x y result /\ sub_post_real x y result }
...
@@ -50,7 +50,7 @@ module Single
...
@@ -50,7 +50,7 @@ module Single
predicate mul_post_real (x:t) (y:t) (r:t) =
predicate mul_post_real (x:t) (y:t) (r:t) =
t'real r = round RNE (t'real x *. t'real y)
t'real r = round RNE (t'real x *. t'real y)
val mul (x y: t) : t
val
safe_
mul (x y: t) : t
requires { [@expl:floating-point overflow]
requires { [@expl:floating-point overflow]
mul_pre_ieee x y \/ mul_pre_real x y }
mul_pre_ieee x y \/ mul_pre_real x y }
ensures { mul_post_ieee x y result /\ mul_post_real x y result }
ensures { mul_post_ieee x y result /\ mul_post_real x y result }
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment