feat: Decimal runtime arithmetic and ready natives #353
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/334-decimal-runtime"
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?
Slice 2 of DECIMAL.md section 14: the runtime arithmetic and the ready natives.
runtime/decimal.c: aDecimalis a counted block of base-1e9 limbs and a scale. It parses text, does+ - *exactly,/to 34 significant digits (half to even), the truncated%,rounded/dividedby the sixRoundingmodes, compare/equals/hash/show, and conversions from and toInt64,UInt64andFloat64. The C tests inruntime/tests/decimal_test.ccover the #332 table and run in tier B.std/number: every native of section 10 is declared, plusRounding. NoplannedRuntimeOfentry forDecimalremains innatives.trb.Float64.fromis now qualified by source, because aDecimalconverts throughtorb_decimal_to_f64and not through a cast.Decimalas a two-word counted value (TORB_BLOCK_DECIMAL, counted kindDecimalDigits).torb_natives.handmachine_natives.care regenerated.tests/conformance/decimal-arithmetic.trbruns natively and in the VM with the leak gate.BACKEND.mdand theDecimalreference page reflect that arithmetic runs while literals are still planned (#335). The skills mirror is updated.Seed impact: none (the compiler does not use
Decimal), so this is afeat(runtime)commit and afeat(natives)commit.The allocation budget of the new conformance program is 543 blocks, the count CI reported (
decimal-arithmetic.allocations).Rebased onto
mainafter theFloat32natives landed:machine_natives.cholds both sets, the comparison test namesFloat32.compareandDecimal.compare, and thenumber.mddeclaration blocks list theDecimalconversions and members.Closes #334
2e225e041291a24f2586torb_decimal_*) and ready natives #33491a24f2586c7c2f9c4f3torb_decimal_*) and ready natives #334Approved at
c7c2f9c.Checklist
runtime/tests/decimal_test.c(tier B),compiler/tests/natives.test.trb,emit-c.test.trband the new conformance programdecimal-arithmetic.trb(native + VM, leak gate, allocation budget 543). CI is green for this head (tier A, tier B, bootstrap, same-C, pdisc, commit messages).runtime/decimal.cin full. Base-1e9 add/sub/mul, Knuth D (estimate correction and add-back), sticky digit for the inexact/, single-roundingdividedvia remainder against half the divisor, truncated%, and the 34-digit round-to-10..0 carry case all check out. The hand-traced expected rows of the conformance output (modes,%,/scales,-0.00) match. Scale overflow and divide-by-zero panic cleanly;parsebounds the exponent before it can overflow.isNichePayloadcorrectly excludesDecimal(zero is a null pointer).Decimal, so no seed impact.Non-blocking
1e2000000000 + 1) end in an out-of-memory panic rather than a dedicated diagnostic. Acceptable for now; worth a note in DECIMAL.md if not already there.