Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Eliminate .toDouble roundtrips in opaque type arithmetic#134

Merged
speedcom merged 1 commit intomainfrom
refactor/opaque-toDouble-sweep
Mar 12, 2026
Merged

Eliminate .toDouble roundtrips in opaque type arithmetic#134
speedcom merged 1 commit intomainfrom
refactor/opaque-toDouble-sweep

Conversation

@speedcom
Copy link
Contributor

@speedcom speedcom commented Mar 12, 2026

Summary

  • ~18 sites converted from PLN(x.toDouble * y.toDouble) / Ratio(a.toDouble OP b.toDouble) to direct opaque type arithmetic
  • PLN * Double, PLN * Ratio, Ratio * Double operators used instead of unwrap-compute-rewrap
  • .toDouble pushed to boundaries only (rng comparison, Math.min on mixed types, kahanSumBy)
  • Files: FirmInit, FirmEntry, Jst, Household, EquityInit, PriceEquityStep, Firm, Banking, CorporateBondMarket

Test plan

  • sbt compile — 0 errors
  • sbt test — all pass
  • Verify no behavioral change in MC output

- FirmInit/FirmEntry: use PLN * Double and PLN * Ratio directly
  instead of PLN(x.toDouble * y.toDouble)
- Jst: propertyTax uses PLN * Double / 12.0
- Household: social800Rate uses PLN * Double
- EquityInit: separate PLN construction from Ratio multiplication
- PriceEquityStep: klRatios(i) * Double instead of unwrap-multiply-wrap
- Firm: push .toDouble to boundary (Ratio arithmetic stays in Ratio)
- Banking: nplRatio * factor stays as Ratio, .toDouble at boundary
- CorporateBondMarket: cyclicalSpread computed as Rate, not Double
@speedcom speedcom merged commit f117536 into main Mar 12, 2026
2 checks passed
@speedcom speedcom deleted the refactor/opaque-toDouble-sweep branch March 12, 2026 12:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant