feat(runtime,backend): Float32 arithmetic, compare, Show and narrowing from Float64 #352
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/35-float32-arithmetic"
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?
Task: #35 (slice 1: Float32 arithmetic, comparison, text and narrowing from Float64).
What
torb_parse_f32(reads aFloat64, rounds once, a finite text beyond the range is an infinity as forFloat64),torb_show_f32now searches the shortest text that reads back to the samefloat, andtorb_convert_f64_f32_checked(ties to even, nan/inf pass through, fails only from 2^128 - 2^103 on, with an explicit check so no out-of-rangedoubletofloatcast happens).backend/c/natives.trb): the planned Float32 rows become ready -numericMembers,signedMembersandcompare(torb_compare_f32) likeFloat64- plus the new rowFloat32.tryFrom(Float64).runtime/machine_natives.candtorb_natives.hregenerated for the four runtime rows (263 thunks).float *out-parameter goes through a temporary, because a register holds afloatas the bits of thedoubleit equals.Float32interpolation part is the text of itsShow(torb_show_f32), not theFloat64formatter.ir/constant.trb, bytecodeemit.trb): aFloat32result is rounded to binary32 (viastd/binary/number'sfloat32Pattern), so a folded constant has the bits the run time computes; an integer literal typed as a float now folds as a float (const x: Float32 = 1 / 3is0.33333334, not0).extend Float32 with TryFrom<Float64, NumberRangeError>, the Float32 type doc andReal"# Open" updated.std/encoding's Float32 comment updated.Seed rule: new natives only, one commit; nothing in
std/or the compiler uses them (the migration ofstd/binaryis #349,bits()/ofBits#348).Not changed: the checker's own constant evaluator (
semantics/checker/constant.trb) still computes aFloat32constant inFloat64; it only feeds diagnostics.Test
tests/conformance/float32.trb: the 32-vs-64-bit sum, 2^24+1 / 2^24+3 rounding,%, negation,absolute, overflow to inf, subnormals, signed zero, nan comparisons andcompare, the parse/show round trip, narrowing at the edges (halfway to 2^128, 3.5e38, 1e-50, nan/inf), and constant folding equal to the run time. Expectations computed with binary32 rounding outside the toolchain.floats.trb: the Float32 line now also shows the named constants.torb_show_f32/torb_parse_f32andtorb_convert_f64_f32_checked.float3282 blocks,floats28 -> 34 (its new line shows the five named Float32 constants).Closes #35
a8d3d8b9c9029dd21400029dd214009772502a4f9772502a4fc6bd203180Float32arithmetic, comparison, text and narrowing fromFloat64(slice 1) #35Approved. Checklist (head
c6bd203):float32.trb(both back ends via CI tier A/B, allocation budgets set),floats.trbextended, C runtime tests fortorb_show_f32/torb_parse_f32/torb_convert_f64_f32_checked, manifest test updated. CI combined status success on this head (skipped jobs are the other-OS runners).0x1.ffffffp127is the exact halfway point to 2^128 and ties to even go to infinity, so>=is right;torb_parse_f32uses the same cut-off. Show/parse round trip is consistent because both read throughstrtodthen(float). Thefloat *out-parameter via a temporary matches the register representation. Folding rounds each result to binary32; double rounding is innocuous for+ - * /at 53 >= 2*24+2 bits, so folded constants match the run time.Realfor Float32 andstd/binarymigration stay out.Non-blocking:
floatingValuesays+ - * /of two Float32 are "exact in a Float64"; for+/-with widely different exponents that is not exact, only correctly rounded after the second rounding. Wording only.Float32is rounded twice in the compiler (Int to double to float) where C converts it directly; this can differ in the last bit for such literals. Worth a conformance case or a direct path in a follow-up.Float64.bits(),ofBits(_)and the same forFloat32#348bits()/ofBits(_),float32()answers aFloat32#349