Crate ryu_ecmascript

source ·
Expand description

Pure Rust implementation of Ryū, an algorithm to quickly convert floating point numbers to decimal strings.

The PLDI’18 paper Ryū: fast float-to-string conversion by Ulf Adams includes a complete correctness proof of the algorithm. The paper is available under the creative commons CC-BY-SA license.

This Rust implementation is a line-by-line port of Ulf Adams’ implementation in C, https://github.com/ulfjack/ryu. The ryu::raw module exposes exactly the API and formatting of the C implementation as unsafe pure Rust functions. There is additionally a safe API as demonstrated in the example code below. The safe API uses the same underlying Ryū algorithm but diverges from the formatting of the C implementation to produce more human-readable output, for example 0.3 rather than 3E-1.

Examples

extern crate ryu_ecmascript;

fn main() {
    let mut buffer = ryu_ecmascript::Buffer::new();
    let printed = buffer.format(1.234);
    assert_eq!(printed, "1.234");
}

Modules

Unsafe functions that exactly mirror the API of the C implementation of Ryū.

Structs

Safe API for formatting floating point numbers to text.

Traits

A floating point number, f32 or f64, that can be written into a ryu_ecmascript::Buffer.