[][src]Function ryu::raw::pretty_d2s_buffered_n

#[must_use]
pub unsafe fn pretty_d2s_buffered_n(f: f64, result: *mut u8) -> usize

Print f64 to the given buffer and return number of bytes written. Human readable formatting.

At most 24 bytes will be written.

Special cases

This function does not check for NaN or infinity. If the input number is not a finite float, the printed representation will be some correctly formatted but unspecified numerical value.

Please check is_finite yourself before calling this function, or check is_nan and is_infinite and handle those cases yourself.

Safety

The result pointer argument must point to sufficiently many writable bytes to hold Ryū's representation of f.

Example

let f = 1.234f64;

unsafe {
    let mut buffer: [u8; 24] = std::mem::uninitialized();
    let n = ryu::raw::pretty_d2s_buffered_n(f, &mut buffer[0]);
    let s = std::str::from_utf8_unchecked(&buffer[..n]);
    assert_eq!(s, "1.234");
}