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

Opaque type arithmetic: clamp, monthly, eliminate .toDouble#133

Merged
speedcom merged 4 commits intomainfrom
refactor/opaque-clamp
Mar 12, 2026
Merged

Opaque type arithmetic: clamp, monthly, eliminate .toDouble#133
speedcom merged 4 commits intomainfrom
refactor/opaque-clamp

Conversation

@speedcom
Copy link
Contributor

Summary

  • Add clamp(lo, hi) to PLN, Rate, Ratio — replaces Type(Math.max(lo, Math.min(hi, x.toDouble))) pattern
  • Add Rate.monthlyrate / 12.0 with intent (annual → monthly conversion)
  • Convert ~20 sites from Type(Math.max/min(...toDouble...)) to .max(), .min(), .clamp()
  • Eliminate 6 unnecessary .toDouble roundtrips in opaque type arithmetic (PLN+PLN, Rate+Rate, PLN*Rate)
  • Fix mistyped skillDecayRate/scarringRate: RateRatio (monthly increments to Ratio fields, not interest rates)
  • FirmEntry.drawDigitalReadiness return type DoubleRatio

Test plan

  • sbt compile — 0 errors
  • 1244 tests pass
  • Verify no behavioral change in MC output

- PLN, Rate, Ratio gain .clamp(lo, hi) extension method
- ~20 sites converted from Type(Math.max(lo, Math.min(hi, x.toDouble)))
  to opaque-type arithmetic: .max(), .min(), .clamp()
- Fix mistyped skillDecayRate/scarringRate: Rate → Ratio (monthly
  increments to Ratio fields, not interest rates)
- FirmEntry.drawDigitalReadiness return type Double → Ratio
- Add Rate.monthly (annual → monthly rate conversion)
- Replace PLN(x.toDouble + y.toDouble) with x + y
- Replace PLN(x.toDouble * rate.toDouble / 12.0) with x * rate.monthly
- Replace Rate(a.toDouble + b.toDouble + c.toDouble) with a + b + c
- Replace Ratio(...toDouble * smoothing + ...toDouble * smoothing) with
  opaque Ratio/Rate * scalar arithmetic
- GvcTrade.kahanSumBy left as-is (Kahan precision requires Double)
@speedcom speedcom merged commit 526e7ed into main Mar 12, 2026
2 checks passed
@speedcom speedcom deleted the refactor/opaque-clamp branch March 12, 2026 12:41
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