xpile 0.1.615

Polyglot transpile workbench (Python/C/C++/Rust/Ruchy/Lean ↔ Rust/Ruchy/PTX/WGSL/SPIR-V) with provable contracts at every layer.
1
2
3
4
5
6
7
8
9
10
11
12
13
# PMAT-502ch (Tranche 2): str.format with format specs `{:.2f}` / `{:05d}`.
# Each spec is translated to its Rust form by the arg's type; float args are
# admitted when they carry a `.Nf` spec. Positional + spec also works.
def money(x: float) -> str:
    return "${:.2f}".format(x)


def padded(n: int) -> str:
    return "id={:05d}".format(n)


def both(a: float, b: int) -> str:
    return "{:.1f} ({:03d})".format(a, b)