Function float_fast_print::write_f32_shortest [−][src]
pub fn write_f32_shortest<W: Write>(writer: W, num: f32) -> Result<usize>
Converts the given f32
number to a short round-trip base-10 representation
using the efficient Ryū algorithm by Ulf Adams.
This function is ideal for exporting bulk floating-point data to text formats, such as CSV, JSON, or XLSX (Excel 2007 and later).
Examples
use float_fast_print::write_f32_shortest; let mut buffer: Vec<u8> = Vec::with_capacity(32); write_f32_shortest(&mut buffer, 502.1239e29).unwrap(); assert_eq!(&buffer, b"5.021239e31");
Safety
Unlike some other similar code such as the dtoa
crate, this function uses
100% safe Rust code, does not have any external dependencies, does not include
C code, and does not require a heap.
The float_fast_print::exhaustive
test can be used to totally validate the
round-trip behaviour and stability (no panics wih all 2^32 distinct f32
inputs),
guaranteeing safety. Note that this takes some days to complete...