Permalink
Browse files

Add BatFloat.is_finite + tests

  • Loading branch information...
1 parent aa8d044 commit 30ec434564326977f016aad950d11a6f829b8487 @hcarty committed Aug 12, 2012
Showing with 21 additions and 0 deletions.
  1. +15 −0 src/batFloat.ml
  2. +6 −0 src/batFloat.mli
View
@@ -177,6 +177,14 @@ let is_special f =
| FP_subnormal
| FP_zero -> false
+let is_finite f =
+ match classify f with
+ | FP_nan
+ | FP_infinite -> false
+ | FP_normal
+ | FP_subnormal
+ | FP_zero -> true
+
let infinity = Pervasives.infinity
let neg_infinity = Pervasives.neg_infinity
let nan = Pervasives.nan
@@ -351,6 +359,13 @@ end
is_special nan
*)
+(*$T is_finite
+ List.for_all is_finite [1.0; 1e200; 1e-200; 0.0; -0.0; -1.0; -1e200; -1e-200]
+ not (is_finite nan)
+ not (is_finite infinity)
+ not (is_finite neg_infinity)
+*)
+
(*$T
try ignore (Safe_float.add 0. infinity); false with BatNumber.Overflow -> true
try ignore (Safe_float.add 0. neg_infinity); false with BatNumber.Overflow -> true
View
@@ -222,6 +222,12 @@ val is_special : float -> bool
@since 2.0 *)
+val is_finite : float -> bool
+(** [is_finite f] returns [true] if [f] is not [nan] or [+/- infinity],
+ [false] otherwise.
+
+ @since 2.0 *)
+
(** {6 Constants} *)
(** Special float constants. It may not be safe to compare

0 comments on commit 30ec434

Please sign in to comment.