package dtoa

  1. Overview
  2. Docs
Converts OCaml floats into strings (doubles to ascii, 'd to a'), using the efficient Grisu3 algorithm

Install

Dune Dependency

Authors

Maintainers

Sources

dtoa-v0.3.2.tbz
sha256=b613700295897ed57c2f4f1a6809084813124d9fd66c5dd5334f20dc32b0707e
sha512=16b31cd2af6b51be702dc9b9f6837e2c213f15cab634afe6c7bb6c7e827071af4694976c1d7e4e713289f41c330f2ec25685b7b26734007889513d462a2e9518

Description

This is a (partial) port of Google's double-conversion library from C++ to C.

Published: 17 Jun 2019

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 returning 123e6 instead of 123000000 or 1.23e+08.

  • g_fmt : float -> string: formats the float in the same way as David M. Gay's g_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.

Dependencies (2)

  1. dune >= "1.0"
  2. ocaml >= "4.01.0"

Dev Dependencies (1)

  1. ounit with-test & >= "2.0.0"

Used by (2)

  1. flow_parser >= "0.62.0" & < "0.229.1"
  2. flowtype >= "0.62.0"

Conflicts

None

OCaml

Innovation. Community. Security.