package dtoa
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=d8f4608c9e92b29e25ea31f3bf5fccab396899094990a2d59d15c6e8a3c9ee3e
sha512=58dace1eccd9b55e4e3450c1c6767646ae9551169848b127283b7332cf25c0e0bdd7c8fdf987d55b71e10f82915e59c5439c3ae391696589b490c9184a3dd87c
Description
This is a (partial) port of Google's double-conversion library from C++ to C.
Published: 27 Feb 2023
README
ocaml-dtoa
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.
Current Status
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 returning123e6
instead of123000000
or1.23e+08
.g_fmt : float -> string
: formats the float in the same way as David M. Gay'sg_fmt
.
The underlying fast_dtoa()
function computes the significand and exponent, which are formatted by the above functions in dtoa_stubs.c
. It is a port of the double-conversion
library from C++ to C.
Many features of double-conversion
are still missing. Patches are welcome!
License
ocaml-dtoa
is MIT-licensed.
Author
ocaml-dtoa
was created by Facebook for the Flow project.
Dev Dependencies (1)
-
ounit2
with-test
Used by (2)
-
flow_parser
>= "0.62.0" & < "0.229.1"
-
flowtype
>= "0.62.0"
Conflicts
None