lib/fmt/fmttest: inline -2.5 literal in 3 f64 rows (post-#40)

Pre-#40 wwstage's UNTYPED-float fold for `-2.5` was broken, so the
three f64-sign tests (fprintf_f64_neg, fprintf_f64_sign_plus,
asprintf_f64) used a `let nv: f64 = -2.5;` indirection to dodge it.
With #40 (session-3 commit 4d6a19f) landed, the wwstage variant-
widen N_UNARY-of-N_FLOATLIT fold renders the literal directly on
both stages. Indirection inlined; workaround comment blocks dropped.
Kept the sign-fold WHY in fprintf_f64_sign_plus (genuine semantic,
not a workaround note).
This commit is contained in:
2026-05-18 00:30:58 +09:00
parent 225ee97f5c
commit a7700f201b

View File

@@ -519,24 +519,11 @@ fn closedstream(s: *io.stream) void = {
match (c) { case void => {}; case io.closed => fail(); };
};
// Negative-valued f64 rendered through fmt. PENDING task #40 (cstage
// variant-widen drops payload on N_UNARY-of-N_FLOATLIT, residual of
// #30): the literal-arg form below renders as "0" on cstage today —
//
// fmt.fprintf(&s, "{}", -2.5) // ✗ cstage: "0"
// // ✓ wwstage: "-2.5"
//
// Workaround until #40 lands: bind to a typed local so the widen
// hits the post-#30 N_IDENT path. Matches the cast form
// (`-2.5: f64`), which also works on both stages. Realistic caller
// shape (negatives usually arrive through a variable, not as a
// literal printf arg). Probe: .ai/probe_f64_unary_neg.ww.
@test fn fprintf_f64_neg() void = {
let mem: memio.state;
let s: io.stream;
memio.dynamic(&mem, &s);
let nv: f64 = -2.5;
let r: (i32 | io.closed) = fmt.fprintf(&s, "{}", nv);
let r: (i32 | io.closed) = fmt.fprintf(&s, "{}", -2.5);
match (r) {
case let n: i32 => { if (n != 4) { fail(); }; };
case io.closed => fail();
@@ -591,15 +578,12 @@ fn closedstream(s: *io.stream) void = {
};
// Sign-mod fold: '+' on positive, '-' still wins on negative (the
// natural '-' from strconv is peeled and signof reapplies). Negative
// routed through a typed local — same task #40 workaround as
// fprintf_f64_neg above.
// natural '-' from strconv is peeled and signof reapplies).
@test fn fprintf_f64_sign_plus() void = {
let mem: memio.state;
let s: io.stream;
memio.dynamic(&mem, &s);
let nv: f64 = -1.5;
let r: (i32 | io.closed) = fmt.fprintf(&s, "{:+} {:+}", 1.5, nv);
let r: (i32 | io.closed) = fmt.fprintf(&s, "{:+} {:+}", 1.5, -1.5);
match (r) {
case let n: i32 => { if (n != 9) { fail(); }; }; // "+1.5 -1.5"
case io.closed => fail();
@@ -677,11 +661,9 @@ fn closedstream(s: *io.stream) void = {
};
};
// Heap sink + both signs. Negative through typed local per task #40
// workaround (see fprintf_f64_neg comment).
// Heap sink + both signs.
@test fn asprintf_f64() void = {
let nv: f64 = -2.5;
let r: str = fmt.asprintf("{} {}", 1.5, nv);
let r: str = fmt.asprintf("{} {}", 1.5, -2.5);
if (!streq(r, "1.5 -2.5")) { fail(); };
os.free(r.ptr: *void, r.len: u64);
};