number: Float32 arithmetic, comparison, text and narrowing from Float64 (slice 1) #35
Labels
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
#348 number:
Float64.bits(), ofBits(_) and the same for Float32
torbscript/language
Reference
torbscript/language#35
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Float32is declared (std/number) but no compiled program can compute with it: the C back end lists its ten members (add,subtract,multiply,divide,remainder,negate,absolute,equals,compare,show) andFloat32.tryFrom(String)as planned, there is no conversion from aFloat64down to aFloat32, andRealcannot be implemented for it (LINEAR.md, "Open" item 8). What exists today:floatas the C type of a 32-bit float (backend/c/type.trb),torb_remainder_f32,torb_equal_f32andtorb_compare_f32in the runtime,TORB_KIND_F32in the VM (runtime/machine.c, rounds tofloatafter each operation), andFloat64.from(Float32)as an intrinsic. Missing: the intrinsic rows,torb_show_f32,torb_parse_f32, the narrowing conversion, and the constant evaluator, which folds every float in 64 bits whatever its type (double rounding for aFloat32constant).This is slice 1 of the
Float32work; the bit patterns are the follow-up slice and the migration ofstd/binarythe last one (see Dependencies).Source
Float32 with TryFrom<Float64, NumberRangeError>native, then arithmetic in the back endsAcceptance criteria
Float32+ - * / %, unary-,absolute(),==,<,compare(total order,nanabove everything likeFloat64.compare) andShowrun in the C back end and in the VM; every operation rounds to binary32. The ten rows inbackend/c/natives.trbare ready, none planned.Float32.tryFrom(String)parses and"{value}"prints the shortest decimal that parses back to the sameFloat32(torb_parse_f32,torb_show_f32; notation as forFloat64).Float32 with TryFrom<Float64, NumberRangeError>(the record's choice): rounds to nearest even, passesnanand the infinities through, fails with aNumberRangeErroronly for a finite value that would round to an infinity.Float64.from(Float32)stays exact.Float32folds to the same bits the run time computes (const a: Float32 = 0.1 + 0.2equals the same sum on variables); a case where this cannot be guaranteed is not folded.tests/conformance/run identically in both back ends (extendfloats.trb'sFloat32line that says "no back endShowyet"): arithmetic, rounding (a sum that differs between 32 and 64 bits), overflow to infinity, subnormals, signed zero,nancomparisons,compare, parse/show round trip, the narrowing conversion at the edges.docs/design/LINEAR.mditem 8 updated, theFloat32paragraph ofstd/number's doc comments,docs/ROADMAP.md's planned-natives line,skills/regenerated.Design record point
LINEAR.md "Open" item 8 (the order of work and the conversion's shape); BINARY.md section 10 for what it unlocks.
RealforFloat32(needssquareRootand the<math.h>family inf32) stays out of this slice.Seed impact
Yes. New natives (
Float32.tryFrom(Float64),torb_show_f32,torb_parse_f32) and ready intrinsic rows: land as one or two Conventional Commits (teach, then docs/tests); nothing instdmigrates onto them in this slice, so the seed refresh (Torben's) is only needed before thestd/binaryslice.Dependencies
None. Blocks the
Float64.bits()/Float32.bits()slice.Moved from the planning lists of the docs; the design record stays the specification.
[loop:torbscript] intake: in scope (author orion, label loop).
Float32arithmetic and float bit patterns (ROADMAP planned natives, BINARY.md section 10). Touches natives, checker and both back ends (opus/high worker), likely the seed; NaN payload and rounding semantics may need a design-record entry, to settle in refine. Release freeze for 0.1.0 (2026-10-06) holds new PRs, next: refine (queued)[loop:torbscript] refine: still queued behind the intake order. next: waiting (ready buffer full: #4, #163, #164, #223 are ready) until 2026-10-10T04:00:00Z
[loop:torbscript] claim refine by session:loop-torbscript-20261012 until 2026-10-12T23:05Z
Float64.bits(),ofBits(_)and the same forFloat32#348number:to number:Float32arithmetic and the bit patterns of floatsFloat32arithmetic, comparison, text and narrowing fromFloat64(slice 1)Float64.bits(),ofBits(_)and the same forFloat32[loop:torbscript] decided by the loop: (1) Slice the work into three issues: #35 (arithmetic, comparison, text, narrowing), #348 (
bits()/ofBits(_)on both float types, blocked by #35), #349 (migratestd/binary, blocked by #348 and by the seed refresh); each fits one PR of one or two commits, only #35 isready. Why: the two-commit seed rule forces the migration after a refresh, and the natives are independent of the arithmetic. (2) Narrowing isFloat32 with TryFrom<Float64, NumberRangeError>as LINEAR.md item 8 specifies, rounding to nearest even, passingnan/infinities through, failing only for a finite value that rounds to an infinity; no new name invented. (3)Float32constants must fold to the run-time bits: measured in the code,checker/constant.trbfolds every float in 64 bits whatever its type, which would double-round aFloat32constant, so it is an acceptance criterion. (4) Existing pieces measured by reading main:floatC type,torb_remainder_f32/equal_f32/compare_f32,TORB_KIND_F32in the VM andFloat64.from(Float32)exist;show/parsefor f32 and the ten intrinsic rows do not. (5)RealforFloat32stays out of scope (needs<math.h>f32 family). No owner question: all of this is internal and technical, and thefloat32()return type change was planned by BINARY.md section 10 before 1.0.Float64.bits(),ofBits(_)and the same forFloat32#348bits()/ofBits(_),float32()answers aFloat32#349[loop:torbscript] refine: rescoped to slice 1 (title and body updated: testable acceptance criteria, design record point LINEAR.md item 8, seed impact yes), follow-ups #348 and #349 created and chained; label ready set, next: implement (opus/high worker, touches checker constant folding, C back end, runtime and VM). Refine worker usage: roughly 100k tokens.
[loop:torbscript] claim implement by session:loop-torbscript-20261012 until 2026-10-13T03:10Z
[loop:torbscript] implement: PR #352 open, CI green, next: review
One commit (
feat(runtime,backend), new natives only, nothing in std or the compiler uses them). Float32 arithmetic,==,<,compare,Show,tryFrom(String)andtryFrom(Float64)in both back ends, constant folding rounded to binary32, new conformance programfloat32.trb, runtime C tests, docs and skills updated. Not changed: the checker's own constant evaluator still folds a Float32 in Float64 (diagnostics only).Tokens: about 0.5M counted after a context compaction; the part before it is not metered.
Float64.bits(),ofBits(_)and the same forFloat32#348bits()/ofBits(_),float32()answers aFloat32#349bits()/ofBits(_),float32()answers aFloat32#349