fix(float): make Float.{min,max} compliant with revised IEEE754

closes #220
This commit is contained in:
Simon Cruanes 2018-05-14 18:07:38 -05:00
parent e825bf2916
commit 841dac234a

View file

@ -36,7 +36,7 @@ let max_finite_value = Pervasives.max_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 sub = (-.)
@ -47,16 +47,20 @@ let abs = Pervasives.abs_float
let scale = ( *. )
let min (x : t) y =
if is_nan x || is_nan y then nan
else if x < y then x else y
match Pervasives.classify_float x, Pervasives.classify_float y with
| FP_nan, _ -> y
| _, FP_nan -> x
| _ -> if x < y then x else y
let max (x : t) y =
if is_nan x || is_nan y then nan
else if x > y then x else y
match Pervasives.classify_float x, Pervasives.classify_float y with
| FP_nan, _ -> y
| _, FP_nan -> x
| _ -> if x > y then x else y
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
type 'a printer = Format.formatter -> 'a -> unit