ryu_ecmascript/lib.rs
1//! Pure Rust implementation of Ryū, an algorithm to quickly convert floating
2//! point numbers to decimal strings.
3//!
4//! The PLDI'18 paper [*Ryū: fast float-to-string conversion*][paper] by Ulf
5//! Adams includes a complete correctness proof of the algorithm. The paper is
6//! available under the creative commons CC-BY-SA license.
7//!
8//! This Rust implementation is a line-by-line port of Ulf Adams' implementation
9//! in C, [https://github.com/ulfjack/ryu][upstream]. The [`ryu::raw`][raw]
10//! module exposes exactly the API and formatting of the C implementation as
11//! unsafe pure Rust functions. There is additionally a safe API as demonstrated
12//! in the example code below. The safe API uses the same underlying Ryū
13//! algorithm but diverges from the formatting of the C implementation to
14//! produce more human-readable output, for example `0.3` rather than `3E-1`.
15//!
16//! [paper]: https://dl.acm.org/citation.cfm?id=3192369
17//! [upstream]: https://github.com/ulfjack/ryu
18//! [raw]: raw/index.html
19//!
20//! # Examples
21//!
22//! ```rust
23//! extern crate ryu_ecmascript;
24//!
25//! fn main() {
26//! let mut buffer = ryu_ecmascript::Buffer::new();
27//! let printed = buffer.format(1.234);
28//! assert_eq!(printed, "1.234");
29//! }
30//! ```
31
32#![no_std]
33#![doc(html_root_url = "https://docs.rs/ryu/0.2.6")]
34#![cfg_attr(
35 feature = "cargo-clippy",
36 allow(
37 cast_lossless,
38 cyclomatic_complexity,
39 many_single_char_names,
40 needless_pass_by_value,
41 unreadable_literal,
42 )
43)]
44
45#[cfg(feature = "no-panic")]
46extern crate no_panic;
47
48mod buffer;
49mod common;
50mod d2s;
51#[cfg(not(feature = "small"))]
52mod d2s_full_table;
53mod d2s_intrinsics;
54#[cfg(feature = "small")]
55mod d2s_small_table;
56mod digit_table;
57mod f2s;
58mod pretty;
59
60pub use buffer::{Buffer, Float};
61
62/// Unsafe functions that exactly mirror the API of the C implementation of Ryū.
63pub mod raw {
64 pub use d2s::d2s_buffered_n;
65 pub use f2s::f2s_buffered_n;
66}