Fix BigDecimal arbitrary magnitude coverage and constrained shrinking - #8281
Closed
adrian-gierakowski wants to merge 1 commit into
Closed
adrian-gierakowski wants to merge 1 commit into
adrian-gierakowski wants to merge 1 commit into
Conversation
A one-sided decimal bound previously fixed every sample at scale 20. Combined with size-limited bigint coefficients, a positive decimal at size 10 had only 101 possible values, all close to zero. Unconstrained decimals also failed to cover large magnitudes at small sizes. Generate a mixture of ordinary decimal amounts and representative wide scales, with explicit coefficient ranges independent of collection size. Include magnitudes beyond floating-point overflow and underflow while keeping ordinary values common and coefficient widths manageable. Project decimal constraints onto each scale using sign-correct floor and ceiling rules, skip grids without valid coefficients, and include boundary scales so narrow and high-precision intervals remain constructible without rejection sampling. Generate offsets from the allowed boundary closest to zero so shrinking a coarse-scale sample still reaches the exact inclusive boundary. Add deterministic coverage at sizes 0, 1 and 10, positive and negative one-sided bounds, inclusive/exclusive narrow intervals, singleton and extreme-scale bounds, valid shrink candidates, exact boundary shrinking, and replay. This change does not depend on changing BigInt generation. Validation: - pnpm test --run packages/effect/test/unstable/arbitrary/BigDecimal.test.ts packages/effect/test/unstable/arbitrary/Arbitrary.test.ts (183 tests) - pnpm check - pnpm lint-fix - pnpm lint All commands ran in the repository's Nix development shell.
🦋 Changeset detectedLatest commit: 9637577 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
adrian-gierakowski
requested a deployment
to
fork
September 17, 2026 16:01 — with
GitHub Actions
Waiting
adrian-gierakowski
requested a deployment
to
fork
September 17, 2026 16:01 — with
GitHub Actions
Waiting
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
Contributor
|
Closing in favor of #8296 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A one-sided BigDecimal bound fixes every generated value at scale 20. With the default size 10, a strictly positive decimal consequently has only 101 possible values, all between 1e-20 and 1.01e-18. Increasing the sample count cannot improve that range. Unconstrained decimals also miss large magnitudes at small sizes.
Change
Mix ordinary decimal amounts with representative wide scales and explicit coefficient ranges. This exercises both signs, values beyond JavaScript floating-point range, and nonzero values below its minimum, while keeping ordinary amounts common.
Project inclusive and exclusive bounds onto each scale using exact integer rounding, omit empty grids, and include boundary scales for narrow or high-precision intervals. Generate offsets from the permitted boundary nearest zero so even coarse-scale samples shrink to the exact inclusive boundary.
This PR is independent of the separate BigInt arbitrary change.
Validation
BigDecimal.test.tsandArbitrary.test.ts.pnpm check,pnpm lint-fixandpnpm lintpassed in the repository's Nix development shell.The commit was validated against Effect 4.0.0-rc.115 (
4a05d4914).