Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove write_float_fast and write_std_float_fast #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### Removed

- Removed undocumented and unused functions `write_float_fast` and
`write_std_float_fast` from `Yojson`, `Yojson.Basic` and `Yojson.Safe`
(@sim642, #149)

### Changed

### Fixed
Expand Down
37 changes: 2 additions & 35 deletions lib/write.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,9 @@ let float_needs_period s =
false

(*
Both write_float_fast and write_float guarantee
that a sufficient number of digits are printed in order to
allow reversibility.

The _fast version is faster but often produces unnecessarily long numbers.
Guarantees that a sufficient number of digits are printed in order to allow
reversibility.
*)
(* unused *)
let write_float_fast ob x =
match classify_float x with
FP_nan ->
Buffer.add_string ob "NaN"
| FP_infinite ->
Buffer.add_string ob (if x > 0. then "Infinity" else "-Infinity")
| _ ->
let s = Printf.sprintf "%.17g" x in
Buffer.add_string ob s;
if float_needs_period s then
Buffer.add_string ob ".0"

let write_float ob x =
match classify_float x with
FP_nan ->
Expand Down Expand Up @@ -192,23 +176,6 @@ let json_string_of_float x =
Buffer.contents ob


(* unused *)
let write_std_float_fast ob x =
match classify_float x with
FP_nan ->
json_error "NaN value not allowed in standard JSON"
| FP_infinite ->
json_error
(if x > 0. then
"Infinity value not allowed in standard JSON"
else
"-Infinity value not allowed in standard JSON")
| _ ->
let s = Printf.sprintf "%.17g" x in
Buffer.add_string ob s;
if float_needs_period s then
Buffer.add_string ob ".0"

let write_std_float ob x =
match classify_float x with
FP_nan ->
Expand Down
2 changes: 0 additions & 2 deletions lib/write.mli
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ val write_int : Buffer.t -> int -> unit
#ifdef FLOAT
val write_float : Buffer.t -> float -> unit
val write_std_float : Buffer.t -> float -> unit
val write_float_fast : Buffer.t -> float -> unit
val write_std_float_fast : Buffer.t -> float -> unit
val write_float_prec : int -> Buffer.t -> float -> unit
val write_std_float_prec : int -> Buffer.t -> float -> unit
#endif
Expand Down