Skip to content

Commit 1353262

Browse files
committed
PR#5739: Printf.printf "%F" and nan/infinity/neg_infinity.
(Reflecting commit r13910 on version/4.01) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13911 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent 055d5c0 commit 1353262

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Bug fixes:
108108
- PR#5734: improved Win32 implementation of Unix.gettimeofday
109109
- PR#5735: %apply and %revapply not first class citizens
110110
- PR#5738: first class module patterns not handled by ocamldep
111+
- PR#5739: Printf.printf "%F" (-.nan) returns -nan
111112
- PR#5747: 'unused open' warning not given when compiling with -annot
112113
- PR#5752: missing dependencies at byte-code link with mlpack
113114
- PR#5758: Compiler bug when matching on floats

stdlib/printf.ml

+11-5
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,13 @@ let format_float_lexeme =
454454
valid_float_loop 0 in
455455

456456
(fun sfmt x ->
457-
let s = format_float sfmt x in
458457
match classify_float x with
459-
| FP_normal | FP_subnormal | FP_zero -> make_valid_float_lexeme s
460-
| FP_nan | FP_infinite -> s)
458+
| FP_normal | FP_subnormal | FP_zero ->
459+
make_valid_float_lexeme (format_float sfmt x)
460+
| FP_infinite ->
461+
if x < 0.0 then "neg_infinity" else "infinity"
462+
| FP_nan ->
463+
"nan")
461464
;;
462465

463466
(* Decode a format string and act on it.
@@ -540,8 +543,11 @@ let scan_format fmt args n pos cont_s cont_a cont_t cont_f cont_m =
540543
| 'F' as conv ->
541544
let (x : float) = get_arg spec n in
542545
let s =
543-
if widths = [] then Pervasives.string_of_float x else
544-
format_float_lexeme (extract_format_float conv fmt pos i widths) x in
546+
format_float_lexeme
547+
(if widths = []
548+
then "%.12g"
549+
else extract_format_float conv fmt pos i widths)
550+
x in
545551
cont_s (next_index spec n) s (succ i)
546552
| 'B' | 'b' ->
547553
let (x : bool) = get_arg spec n in

0 commit comments

Comments
 (0)