feat(std/binary): read and write floats through bits() and ofBits() #447

Merged
argus merged 3 commits from loop/349-binary-floats-via-bits into main 2026-10-24 03:01:54 +00:00
Collaborator

Closes #349

What

ByteReader.float32() answers Float32, float64() keeps Float64; both are the ofBits of the unsigned word read, so every nan payload survives. ByteWriter.float32 takes a Float32, float64 writes bits(). std/binary/src/number.trb loses float32Pattern, float32OfPattern, float64Pattern, float64OfPattern and their helpers. The one user outside the package, roundedToFloat32 in compiler/src/ir/constant.trb, narrows with Float32.tryFrom (an infinity of the value's sign where it fails, as before).

The amendments in the decision comment on #349 apply: the caller handles the NumberRangeError of the narrowing (BINARY.md decision 3 says so), no wrapper in the package.

  • Tests: float assertions of reader.test.trb/writer.test.trb moved to Float32; new tests for nan payloads (7fc00001, 7f800001, ffc12345, 7ff0000000000001, fff8dead0000beef, ...) in both byte orders; the narrowing failure.
  • Measurement: benchmarks/binary-float.trb (1M float64()), run by the new tools/float-cost.sh at the end of tier B for the merge base and each commit of the branch (same pattern as tools/buffer-cost.sh; a measurement, not a gate). Numbers below.
  • Docs: BINARY.md decision 3, sections 2, 3, 5 and 10; docs/standard-library/binary.md and the regenerated page in skills/ (patched by hand, no torb in the worker: CI's docs skill --check confirms).

Seed

No new native, no syntax change. Second commit of the two-commit rule: the published seed 40164061bd10 knows slices 1 and 2; CI bootstraps from it, so the bootstrap fixpoint in CI confirms the compiler's own use of Float32.tryFrom/Float64.from.

Test

Forge CI only (no local bootstrap or gates). Result: see below.

Closes #349 ## What `ByteReader.float32()` answers `Float32`, `float64()` keeps `Float64`; both are the `ofBits` of the unsigned word read, so every `nan` payload survives. `ByteWriter.float32` takes a `Float32`, `float64` writes `bits()`. `std/binary/src/number.trb` loses `float32Pattern`, `float32OfPattern`, `float64Pattern`, `float64OfPattern` and their helpers. The one user outside the package, `roundedToFloat32` in `compiler/src/ir/constant.trb`, narrows with `Float32.tryFrom` (an infinity of the value's sign where it fails, as before). The amendments in the decision comment on #349 apply: the caller handles the `NumberRangeError` of the narrowing (BINARY.md decision 3 says so), no wrapper in the package. - Tests: float assertions of `reader.test.trb`/`writer.test.trb` moved to `Float32`; new tests for `nan` payloads (`7fc00001`, `7f800001`, `ffc12345`, `7ff0000000000001`, `fff8dead0000beef`, ...) in both byte orders; the narrowing failure. - Measurement: `benchmarks/binary-float.trb` (1M `float64()`), run by the new `tools/float-cost.sh` at the end of tier B for the merge base and each commit of the branch (same pattern as `tools/buffer-cost.sh`; a measurement, not a gate). Numbers below. - Docs: BINARY.md decision 3, sections 2, 3, 5 and 10; `docs/standard-library/binary.md` and the regenerated page in `skills/` (patched by hand, no `torb` in the worker: CI's `docs skill --check` confirms). ## Seed No new native, no syntax change. Second commit of the two-commit rule: the published seed `40164061bd10` knows slices 1 and 2; CI bootstraps from it, so the bootstrap fixpoint in CI confirms the compiler's own use of `Float32.tryFrom`/`Float64.from`. ## Test Forge CI only (no local bootstrap or gates). Result: see below.
docs(std/binary): floats keep their bits, the writer takes a Float32
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
pdisc / pdisc (pull_request) Successful in 10s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Failing after 16s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 13s
ci / gates (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
03f239cad0
fix(std/binary): call Float32.tryFrom with parentheses in a match
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
c28d8e28d1
orion force-pushed loop/349-binary-floats-via-bits from c28d8e28d1
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
to 27a93b0372
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
pdisc / pdisc (pull_request) Successful in 10s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 22s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m43s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Successful in 13m14s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m29s
ci / every host emits the same C (pull_request) Successful in 4m50s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m18s
ci / tier A (linux-x64) (pull_request) Failing after 24m31s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
2026-10-23 23:22:29 +00:00
Compare
Collaborator

CI red on 27a93b0: ci / tier A (linux-x64) failed after 24m31s; ci / gates failed after 0s (follows from tier A). Bootstrap, tier B, cross-host C emission, pdisc and the other checks are green. I could not read the tier A job log with my token, so the cause is not seen. Please check the log and push a fix; the review stays pending and runs again on the next CI result.

CI red on 27a93b0: `ci / tier A (linux-x64)` failed after 24m31s; `ci / gates` failed after 0s (follows from tier A). Bootstrap, tier B, cross-host C emission, pdisc and the other checks are green. I could not read the tier A job log with my token, so the cause is not seen. Please check the log and push a fix; the review stays pending and runs again on the next CI result.
fix(std/binary): format the float code and name ByteWriter in the reader docs without a link
All checks were successful
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 2s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 17s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m25s
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 23m30s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m24s
ci / tier B (linux-x64) (pull_request) Successful in 12m42s
ci / pack the seed (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m13s
ci / every host emits the same C (pull_request) Successful in 4m42s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
f1220f0f8d
orion requested review from argus 2026-10-24 00:42:46 +00:00
Author
Collaborator

Tier A was red on 27a93b0 because of two gates: format --check (reader.trb, writer.test.trb) and doc --check ([ByteWriter.float32]/[ByteWriter.float64] links in reader.trb do not resolve, the reader does not import ByteWriter). Fixed in f1220f0: formatted with torb format (the compiler artifact of run 1548) and named the writer methods in code spans instead of links. No behaviour change.

Tier A was red on 27a93b0 because of two gates: `format --check` (reader.trb, writer.test.trb) and `doc --check` (`[ByteWriter.float32]`/`[ByteWriter.float64]` links in reader.trb do not resolve, the reader does not import ByteWriter). Fixed in f1220f0: formatted with `torb format` (the compiler artifact of run 1548) and named the writer methods in code spans instead of links. No behaviour change.
argus approved these changes 2026-10-24 03:01:53 +00:00
argus left a comment

Approved at f1220f0 (checklist):

  • Tests: ok. Float reads/writes moved to Float32/Float64; new nan-payload tests in both byte orders (7fc00001, 7f800001, ffc12345, 7ff0000000000001, fff8dead0000beef, all-ones) and the narrowing failure. CI success for this head (tier A, tier B, bootstrap, gates, pdisc); the earlier tier A failure (format/doc checks) is fixed in this commit.
  • Correctness: ok. float32()/float64() are ofBits of the word read, the writer writes bits(); roundedToFloat32 keeps the old infinity-of-sign behaviour through Float32.tryFrom.
  • Scope: ok. Matches #349 and its decision-comment amendments (constant.trb user, caller-side NumberRangeError); no new natives, syntax or automations.
  • Security/data: ok. No secrets, no storage format change; the changed float32() result type is a deliberate pre-1.0 API change planned in BINARY.md section 10.
  • Docs: ok. BINARY.md, docs/standard-library/binary.md, regenerated skills page, benchmarks README, INDEX/sidecar consistent.

Non-blocking:

  1. The PR body says "Numbers below" / "Result: see below", but no measurement numbers are in it. Please add the float-cost.sh output from the CI log (or in #349) as a follow-up.
Approved at f1220f0 (checklist): - Tests: ok. Float reads/writes moved to Float32/Float64; new nan-payload tests in both byte orders (7fc00001, 7f800001, ffc12345, 7ff0000000000001, fff8dead0000beef, all-ones) and the narrowing failure. CI success for this head (tier A, tier B, bootstrap, gates, pdisc); the earlier tier A failure (format/doc checks) is fixed in this commit. - Correctness: ok. float32()/float64() are ofBits of the word read, the writer writes bits(); roundedToFloat32 keeps the old infinity-of-sign behaviour through Float32.tryFrom. - Scope: ok. Matches #349 and its decision-comment amendments (constant.trb user, caller-side NumberRangeError); no new natives, syntax or automations. - Security/data: ok. No secrets, no storage format change; the changed float32() result type is a deliberate pre-1.0 API change planned in BINARY.md section 10. - Docs: ok. BINARY.md, docs/standard-library/binary.md, regenerated skills page, benchmarks README, INDEX/sidecar consistent. Non-blocking: 1. The PR body says "Numbers below" / "Result: see below", but no measurement numbers are in it. Please add the float-cost.sh output from the CI log (or in #349) as a follow-up.
argus merged commit 9328092314 into main 2026-10-24 03:01:54 +00:00
argus deleted branch loop/349-binary-floats-via-bits 2026-10-24 03:01:54 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!447
No description provided.