FloatingFormatters
Appends canonical shortest-round-trip f16 text from exact stored bits.
Module std.format
import std.format;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
fn
pub const fn FormatTo(Value: readonly f16&, Builder: mut StringBuilder&) -> void;Appends canonical shortest-round-trip f16 text from exact stored bits. Value: Readonly IEEE value borrowed only for this call, including nonfinite values. Builder: Writable UTF-8 destination, retaining any sticky allocation failure. Return: No value; checked finalization reports destination allocation failure. Warning: Runtime builder growth may allocate and invalidates its prior views.
Example
module example.floating_formatting;
from std.format import FormatTo;
from std.text import StringBuilder;
fn Main() -> i32 {
var Builder = StringBuilder();
FormatTo(0.1_f16, Builder);
Builder.Append(' ');
FormatTo(0.1_f32, Builder);
Builder.Append(' ');
FormatTo(0.1_f64, Builder);
Builder.Append(' ');
FormatTo(bit_cast<f64>(0x8000000000000000_u64), Builder);
switch Builder.TryFinalize() {
case .Ok { Value = Text } => {
if Text.View != "0.1 0.1 0.1 -0" { return 1; }
}
case .Err => return 2;
}
return 0;
}fn
pub const fn FormatTo(Value: readonly f32&, Builder: mut StringBuilder&) -> void;Appends canonical shortest-round-trip f32 text from exact stored bits. Value: Readonly IEEE value borrowed only for this call, including nonfinite values. Builder: Writable UTF-8 destination, retaining any sticky allocation failure. Return: No value; checked finalization reports destination allocation failure. Warning: Runtime builder growth may allocate and invalidates its prior views.
fn
pub const fn FormatTo(Value: readonly f64&, Builder: mut StringBuilder&) -> void;Appends canonical shortest-round-trip f64 text from exact stored bits. Value: Readonly IEEE value borrowed only for this call, including nonfinite values. Builder: Writable UTF-8 destination, retaining any sticky allocation failure. Return: No value; checked finalization reports destination allocation failure. Warning: Runtime builder growth may allocate and invalidates its prior views.