aboutsummaryrefslogtreecommitdiff
path: root/kernel/float64.ml
diff options
context:
space:
mode:
authorHugo Herbelin2020-03-29 17:38:38 +0200
committerHugo Herbelin2020-03-29 17:38:38 +0200
commit8d1382b996d9421162839c3f481e866fef06fd41 (patch)
tree0305c0f966f2ce738c4b78d07bc41334cf6a840e /kernel/float64.ml
parent6455f44c7a6babb1f2490eaca216469e0c450a00 (diff)
parented399336b886a062e0e3070314c117d62d9a8af3 (diff)
Merge PR #11859: Warn when non exactly parsing non floating-point
Ack-by: SkySkimmer Reviewed-by: Zimmi48 Reviewed-by: erikmd
Diffstat (limited to 'kernel/float64.ml')
-rw-r--r--kernel/float64.ml13
1 files changed, 10 insertions, 3 deletions
diff --git a/kernel/float64.ml b/kernel/float64.ml
index 299f53e8ab..53fc13b04b 100644
--- a/kernel/float64.ml
+++ b/kernel/float64.ml
@@ -21,12 +21,19 @@ let is_neg_infinity f = f = neg_infinity
(* Printing a binary64 float in 17 decimal places and parsing it again
will yield the same float. We assume [to_string_raw] is not given a
- [nan] as input. *)
+ [nan] or an infinity as input. *)
let to_string_raw f = Printf.sprintf "%.17g" f
(* OCaml gives a sign to nan values which should not be displayed as
- all NaNs are considered equal here *)
-let to_string f = if is_nan f then "nan" else to_string_raw f
+ all NaNs are considered equal here.
+ OCaml prints infinities as "inf" (resp. "-inf")
+ but we want "infinity" (resp. "neg_infinity"). *)
+let to_string f =
+ if is_nan f then "nan"
+ else if is_infinity f then "infinity"
+ else if is_neg_infinity f then "neg_infinity"
+ else to_string_raw f
+
let of_string = float_of_string
(* Compiles a float to OCaml code *)