Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

FloatingFormatters

Appends canonical shortest-round-trip f16 text from exact stored bits.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

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.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library