mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
fix(float): make Float.{min,max} compliant with revised IEEE754
closes #220
This commit is contained in:
parent
e825bf2916
commit
841dac234a
1 changed files with 10 additions and 6 deletions
|
|
@ -36,7 +36,7 @@ let max_finite_value = Pervasives.max_float
|
||||||
|
|
||||||
let epsilon = Pervasives.epsilon_float
|
let epsilon = Pervasives.epsilon_float
|
||||||
|
|
||||||
let is_nan x = (x : t) <> x
|
let is_nan x = Pervasives.classify_float x = Pervasives.FP_nan
|
||||||
|
|
||||||
let add = (+.)
|
let add = (+.)
|
||||||
let sub = (-.)
|
let sub = (-.)
|
||||||
|
|
@ -47,16 +47,20 @@ let abs = Pervasives.abs_float
|
||||||
let scale = ( *. )
|
let scale = ( *. )
|
||||||
|
|
||||||
let min (x : t) y =
|
let min (x : t) y =
|
||||||
if is_nan x || is_nan y then nan
|
match Pervasives.classify_float x, Pervasives.classify_float y with
|
||||||
else if x < y then x else y
|
| FP_nan, _ -> y
|
||||||
|
| _, FP_nan -> x
|
||||||
|
| _ -> if x < y then x else y
|
||||||
|
|
||||||
let max (x : t) y =
|
let max (x : t) y =
|
||||||
if is_nan x || is_nan y then nan
|
match Pervasives.classify_float x, Pervasives.classify_float y with
|
||||||
else if x > y then x else y
|
| FP_nan, _ -> y
|
||||||
|
| _, FP_nan -> x
|
||||||
|
| _ -> if x > y then x else y
|
||||||
|
|
||||||
let equal (a:float) b = a=b
|
let equal (a:float) b = a=b
|
||||||
|
|
||||||
let hash = Hashtbl.hash
|
let hash : t -> int = Hashtbl.hash
|
||||||
let compare (a:float) b = Pervasives.compare a b
|
let compare (a:float) b = Pervasives.compare a b
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue