This is a (partial) port of Google's double-conversion library from C++ to C.
Published: 17 Jun 2019
This library provides a function that converts OCaml floats into strings, using the efficient Grisu3 algorithm.
The Grisu3 algorithm is described in "Printing Floating-Point Numbers Quickly And Accurately with Integers" by Florian Loitsch.
The implementation is adapted from double-conversion.
Currently, this library exposes three functions:
ecma_string_of_float : float -> string: formats the float according to the ECMAScript specification's implementation of Number.prototype.toString. Notably, the output of this function is valid JSON.
shortest_string_of_float : float -> string: formats the float as compactly as possible, for example returning
g_fmt : float -> string: formats the float in the same way as David M. Gay's
Many features of
double-conversion are still missing. Patches are welcome!
ocaml-dtoa is MIT-licensed.
ocaml-dtoa was created by Facebook for the Flow project.