diff options
| author | Pierre-Marie Pédrot | 2020-02-02 18:42:25 +0100 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2020-02-02 18:42:25 +0100 |
| commit | 47c1730d4a7c02ba56d0292143f25772319dd98c (patch) | |
| tree | ac5dc6fab5f206e471da5b0f27e4207937561a01 /kernel/float64.ml | |
| parent | 9c461520c56232e7f7fbebd5134f9e902be1b597 (diff) | |
| parent | e30eab16b2669cfcd63a718fa10a7bc7f6020b8a (diff) | |
Merge PR #11484: Fix 11483 (Performance bug of PrimFLoat.compare with native_compute)
Reviewed-by: maximedenes
Reviewed-by: ppedrot
Diffstat (limited to 'kernel/float64.ml')
| -rw-r--r-- | kernel/float64.ml | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/kernel/float64.ml b/kernel/float64.ml index 3e36373b77..cc661aeba3 100644 --- a/kernel/float64.ml +++ b/kernel/float64.ml @@ -12,7 +12,10 @@ format *) type t = float -let is_nan f = f <> f +(* The [f : float] type annotation enable the compiler to compile f <> f + as comparison on floats rather than the polymorphic OCaml comparison + which is much slower. *) +let is_nan (f : float) = f <> f let is_infinity f = f = infinity let is_neg_infinity f = f = neg_infinity @@ -42,19 +45,20 @@ let abs = abs_float type float_comparison = FEq | FLt | FGt | FNotComparable -let eq x y = x = y +(* See above comment on [is_nan] for the [float] type annotations. *) +let eq (x : float) (y : float) = x = y [@@ocaml.inline always] -let lt x y = x < y +let lt (x : float) (y : float) = x < y [@@ocaml.inline always] -let le x y = x <= y +let le (x : float) (y : float) = x <= y [@@ocaml.inline always] (* inspired by lib/util.ml; see also #10471 *) -let pervasives_compare = compare +let pervasives_compare (x : float) (y : float) = compare x y -let compare x y = +let compare (x : float) (y : float) = if x < y then FLt else ( |
