writeonce/tests/corpus/run/float-arithmetic/fixture.wo
shoney.arickathil 771180fd28 feat: iterations 19 + 17 — Float/Bytes scalars (.wob v5), library kind + internal/
- Float full stack: literals (fraction/exponent; `0..10` still a range), f64
  opcodes 34-41, @table column, WAL bit-exact replay, json fractions in and
  shortest-round-trip out. IEEE-quiet — FDIV never traps where DIV does.
- Bytes: a wo_str with its own class id, so alloc/free/copy are shared but no
  Text builtin accepts one; len/at/slice/eq/concat, base64 both ways, json
  boundary as base64; TEXT_COPY preserves the kind.
- No implicit Int/Float mixing (WO-E201 in the typechecker, not the emitter,
  which picks the opcode from one side and would misread the other).
- One IEEE deviation: float_cmp total order (NaN last, -0.0 == +0.0) for
  indexes and order-by, keys canonicalized to match. `?Float` nil is a
  reserved quiet NaN — the zero word is +0.0, WO_NIL_SCALAR's bits are -2.0.
- Renderer prefers fixed over exponential in 1e-6..1e21: pure shortest makes
  a price of 900.0 read `9e+02`. One renderer for interp/json/float_to_text.
- Fixed en route: lexer double-counted the leading digit; is_scalar_shaped
  took Float/Bytes as Int-shaped; Bytes ownership needed a shared heap-scalar
  predicate or temps never dropped; order-by bit-compared negatives backwards.
- Iteration 17: `kind = "library"` (absent = program; bad value = WO-E109),
  entry-less check mode retiring the `--emit` workaround, Go's `internal/` as
  WO-E108 at the consumer's `use`. Driver-only; VM/.wob/GC untouched.
- Framework reorg: internal/{parse,serve}.wo; http/form.wo split out to keep
  media_type/form_values public (parse.wo had grown public surface).
- Docs: link audit (97 -> 88 broken, conflict markers resolved, 2 duplicate
  stories removed), 00-code-review verified 26/27, iterations re-sequenced.
- Also carries the pre-staged pub(read)/using/#if work from the index.
- Gates: corpus 103/0, test_wal 156/0, web-app 26/0, oop-accept ALL MET.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 19:24:15 +02:00

54 lines
1.8 KiB
Text

-- Iteration 19: Float, the language half. Literal forms, f64 arithmetic,
-- IEEE-quiet division (no DIV0 trap where Int would trap), the explicit
-- bridges in both directions, and the shortest-round-trip rendering that
-- interpolation and json.encode share.
fn main() {
-- literal forms: fraction, leading zero, exponent (both signs)
let price = 9.99
let tiny = 0.125
let big = 2e10
let small = 1.5e-3
print("${price} ${tiny} ${big} ${small}")
-- arithmetic is f64, not integer: 0.1 + 0.2 is famously not 0.3, and
-- printing the truth here is the point of a shortest-round-trip renderer
print("${0.1 + 0.2}")
print("${price * 3.0}")
print("${price - 10.0}")
-- IEEE quiet division: Int would trap DIV0, Float yields infinities and
-- NaN and keeps running
print("${1.0 / 0.0} ${-1.0 / 0.0} ${0.0 / 0.0}")
-- NaN is not equal to itself; that is the contract, not a bug
let nan = 0.0 / 0.0
print_int(nan == nan)
print_int(nan != nan)
-- -0.0 is reachable and distinct in its bits, while IEEE equality says
-- it equals +0.0
let negzero = -0.0
print("${negzero}")
print_int(negzero == 0.0)
-- the explicit bridges: no implicit conversion exists in either direction
let n = 7
print("${float(n) / 2.0}")
print_int(trunc(9.99))
print_int(trunc(-9.99))
-- parse_float: unparseable is NaN, which is what "not a number" means,
-- so there is no ?Float to narrow
print("${parse_float("3.5")} ${parse_float("nope")}")
-- ordering uses IEEE comparisons in the language
print_int(1.5 < 2.5)
print_int(2.5 <= 2.5)
print_int(nan < 1.0)
-- float_cmp is the TOTAL order instead: NaN sorts last, -0.0 == +0.0.
-- This is what an index and an order-by use.
print_int(float_cmp(1.0, 2.0))
print_int(float_cmp(nan, 1.0))
print_int(float_cmp(negzero, 0.0))
}