number: Float64.bits(), ofBits(_) and the same for Float32 #348
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Depends on
Reference
torbscript/language#348
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
std/binarycomputes the IEEE 754 bit patterns of floats in TorbScript from exact powers of two (std/binary/src/number.trb,float64Pattern,float32Pattern, ...), which is slow and loses anan's payload (BINARY.md decision 3). A native bit cast keeps both. This is slice 2 of theFloat32work (slice 1: arithmetic, #35).Source
Float32and the bit patterns"Acceptance criteria
Float64.bits(): UInt64,Float64.ofBits(_ bits: UInt64): Float64,Float32.bits(): UInt32,Float32.ofBits(_ bits: UInt32): Float32instd/number, a bit cast (intrinsic or amemcpy-style runtime function) in the C back end and the VM, identical in both.ofBits(x.bits())has the bits ofxfor every pattern tried, including-0.0, subnormals, infinities andnans with a payload (0x7ff0000000000001,0x7fa00000);1.0.bits() == 0x3ff0000000000000,Float321.0is0x3f800000.tests/conformance/for both widths and both back ends; the constant evaluator does not fold a bit cast of ananinto something aFloatcannot hold.std/numberdoc comments,docs/design/BINARY.mdsection 10 marks the natives built,skills/regenerated.Design record point
BINARY.md section 10 (names
bits()/ofBits(_)and the four types).Seed impact
Yes: four new natives, one or two commits.
std/binarydoes not use them in this slice (that is the migration slice, after the seed refresh).Dependencies
Blocked by slice 1 (#35):
Float32has to compute before its bits are worth reading.Float32arithmetic, comparison, text and narrowing fromFloat64(slice 1)bits()/ofBits(_),float32()answers aFloat32Float32arithmetic, comparison, text and narrowing fromFloat64(slice 1) #35[loop:torbscript] decided by the loop: slice 2 of #35, names
bits()/ofBits(_)and the result typesUInt64/UInt32follow BINARY.md section 10 and the width types ofstd/number. Notreadyuntil #35 is merged (dependency set in the forge). next: waiting (blocked by #35)bits()/ofBits(_),float32()answers aFloat32#349Float32arithmetic, comparison, text and narrowing fromFloat64(slice 1) #35[loop:torbscript] refine: dependency #35 landed (PR #352), label
readyset, next: implement[loop:torbscript] claim implement by session:loop-torbscript-20261013 until 2026-10-13T09:46Z
[loop:torbscript] claim fix by session:loop-torbscript-20261013 until 2026-10-13T13:04Z
bits()/ofBits(_),float32()answers aFloat32#349bits()/ofBits(_),float32()answers aFloat32#349