Function core::num::flt2dec::to_shortest_exp_str
source · pub fn to_shortest_exp_str<'a, T, F>(
format_shortest: F,
v: T,
sign: Sign,
dec_bounds: (i16, i16),
upper: bool,
buf: &'a mut [MaybeUninit<u8>],
parts: &'a mut [MaybeUninit<Part<'a>>]
) -> Formatted<'a>where
T: DecodableFloat,
F: FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> (&'a [u8], i16),
flt2dec
)Expand description
Formats the given floating point number into the decimal form or
the exponential form, depending on the resulting exponent. The result is
stored to the supplied parts array while utilizing given byte buffer
as a scratch. upper
is used to determine the case of non-finite values
(inf
and nan
) or the case of the exponent prefix (e
or E
).
The first part to be rendered is always a Part::Sign
(which can be
an empty string if no sign is rendered).
format_shortest
should be the underlying digit-generation function.
It should return the part of the buffer that it initialized.
You probably would want strategy::grisu::format_shortest
for this.
The dec_bounds
is a tuple (lo, hi)
such that the number is formatted
as decimal only when 10^lo <= V < 10^hi
. Note that this is the apparent V
instead of the actual v
! Thus any printed exponent in the exponential form
cannot be in this range, avoiding any confusion.
The byte buffer should be at least MAX_SIG_DIGITS
bytes long.
There should be at least 6 parts available, due to the worst case like
[+][1][.][2345][e][-][6]
.