Skip to content

v2.1.4: complete the v2.1.3 hygiene cleanup follow-ups#8

Merged
jpurnell merged 1 commit intomainfrom
feature/v2.1.4-cleanup
Apr 8, 2026
Merged

v2.1.4: complete the v2.1.3 hygiene cleanup follow-ups#8
jpurnell merged 1 commit intomainfrom
feature/v2.1.4-cleanup

Conversation

@jpurnell
Copy link
Copy Markdown
Owner

@jpurnell jpurnell commented Apr 8, 2026

Summary

Three follow-up cleanup items deferred from v2.1.3, all bundled here as a single follow-up patch release.

Changes (1 commit)

1. Examples/ String(format:) cleanup

  • MultipleLinearRegressionExample.swift: 22 calls → value.number(N) interpolation
  • LinearRegressionConvenienceExample.swift: 18 calls → value.number(N) interpolation

Both example files now consistent with the rest of the codebase. Examples are not part of the package build target so these violations didn't fail CI before, but they were user-facing reference code that propagated the bad pattern.

2. generateRandomReturns seeded overload

  • New: generateRandomReturns(count:mean:stdDev:using: inout some RandomNumberGenerator)
  • The unseeded original is now a thin wrapper that creates a SystemRandomNumberGenerator and calls the seeded overload — same observable behavior, no breaking change for existing callers
  • Fixed an edge case where Double.random(in: 0.0...1.0) returning exactly 0 would cause log(0) = -inf in the Box-Muller transform (guarded with Double.leastNormalMagnitude)

3. SeededRNG consolidation

5 test files had inlined a local struct SeededRNG using the MMIX LCG (6364136223846793005). Consolidated into a single canonical type:

  • New: TestSupport.MMIXSeededRNG — value type (struct), var state: UInt64, mutating func next() -> Double returning [0, 1], mutating func nextSigned() -> Double returning [-1, 1] (the latter matches what DenseMatrixTests was doing inline)
  • 5 affected files updated to import TestSupport and use MMIXSeededRNG; local struct declarations removed
  • 2 of the 5 needed import TestSupport added (Descriptives Tests.swift, DenseMatrixTests.swift)
  • Bit-identical sequences preserved — the MMIX constants are identical to the local declarations, so no test assertions needed re-tuning

Test plan

  • All 4817 tests pass (no count change from v2.1.3)
  • Zero compiler warnings
  • Zero String(format: matches in Swift files (Sources/, Tests/, Examples/)
  • No struct SeededRNG local declarations remain in Tests/ (only the canonical TestSupport type)
  • DenseMatrixTests's [-1, 1] mapping is preserved via nextSigned()

Compatibility

  • Purely additive at the public API level.
    • generateRandomReturns(count:mean:stdDev:) signature unchanged
    • New generateRandomReturns(count:mean:stdDev:using:) overload added
    • New TestSupport.MMIXSeededRNG type added
    • Existing TestSupport.SeededRNG (Numerical Recipes LCG) untouched
  • No production behavior changes.

Future cleanup not in this PR

DocC .md files in Sources/BusinessMath/BusinessMath.docc/ still contain ~62 String(format:) instances in Swift code samples (12 files). These are documentation, not compiled, but they propagate the bad pattern to users who copy from the docs. Tracked as a future v2.1.5 cleanup.

🤖 Generated with Claude Code

Three items deferred from v2.1.3, all bundled here as a single
follow-up patch release:

1. Examples/ String(format:) cleanup
   - MultipleLinearRegressionExample.swift: 22 calls → value.number(N)
   - LinearRegressionConvenienceExample.swift: 18 calls → value.number(N)
   Both example files now consistent with the rest of the codebase.

2. generateRandomReturns seeded overload
   - Add generateRandomReturns(count:mean:stdDev:using:) accepting any
     RandomNumberGenerator
   - The unseeded original wraps the new overload with a
     SystemRandomNumberGenerator, so existing call sites are unchanged
   - Fixed an edge case where u1 = 0 would cause log(-inf) in
     Box-Muller; guarded with Double.leastNormalMagnitude

3. SeededRNG consolidation
   - Add TestSupport.MMIXSeededRNG (struct, value-type) with the MMIX
     LCG that 5 test files had inlined as local struct declarations
   - Includes nextSigned() for the [-1, 1] mapping that DenseMatrixTests
     was doing inline
   - Bit-identical sequences preserved — no test assertions needed
     re-tuning
   - All 5 affected files updated to import TestSupport and use
     MMIXSeededRNG; local struct declarations removed
   - 2 files needed `import TestSupport` added (Descriptives Tests,
     DenseMatrixTests)

All 4817 tests still pass, zero compiler warnings, no regressions.

DocC .md files still contain ~62 String(format:) instances in Swift
code samples — documented as a future v2.1.5 cleanup. Those files
aren't compiled so they don't break anything, but they propagate the
bad pattern to users copying from the docs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpurnell jpurnell merged commit 25ee811 into main Apr 8, 2026
4 checks passed
@jpurnell jpurnell deleted the feature/v2.1.4-cleanup branch April 8, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant