Repository navigation
Conversation
`exp(sigma^2) - 1` cancels for small `sigma` and is `0` for `sigma^2 < 2^-53`. The fixtures are now generated from the textbook formula in extended precision.
5 of 7 tasks
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
5 of 7 tasks
`stdev` calls `variance`, so its Distributions.jl fixtures, which have the same `exp(sigma^2) - 1` cancellation, no longer match at 0 ULP.
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
kgryte
reviewed
Oct 2, 2026
Signed-off-by: Athan <kgryte@gmail.com>
This comment was marked as outdated.
This comment was marked as outdated.
Planeshifter
approved these changes
Oct 2, 2026
5 of 7 tasks
This branch has not been deployed
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.
Description
This pull request:
stats/base/dists/lognormal/varianceasexpm1( sigma^2 ) * exp( 2*mu + sigma^2 )instead of( exp( sigma^2 ) - 1 ) * exp( 2*mu + sigma^2 )(JS and C).exp(sigma^2) - 1cancels whensigmais small, and is0forsigma^2 < 2^-53:stdevcallsvariance, so it's fixed by this change too. Its fixtures had the same Distributions.jl cancellation, so they're regenerated the same way (with a newsmall_sigma.json). The tolerances are 18 ULP ondataand 1 onsmall_sigma.Fixtures and tests:
runner.jlnow evaluates the textbook formula in 2048-bitBigFloatinstead ofDistributions.var, which uses the same double-precision expression.Distributionsis dropped fromREQUIRE, anddata.jsonis regenerated with the same input ranges.small_sigma.jsonwithsigmalog-spaced over[1e-150, 0.1]. It passes at 3 ULP in JS and native.data.json, the max error is 24 ULP (develop: 45). It comes atsigma ≈ 4.2, where the rounding of2*mu + sigma^2is multiplied by the size of the exponent, so the tolerance goes from 0 to 24. The old 0 only held because the fixture used the same double-precision formula.develop, 1,002 of the 1,110 assertions intest.jsfail. With this change they all pass.Related Issues
None.
Questions
lognormal/skewnesshas the sameexp(sigma^2) - 1cancellation, andlognormal/kurtosishas a worse one:e^{4s} + 2e^{3s} + 3e^{2s} - 6withs = sigma^2. Withu = expm1(s)the latter is exactlyu*(16 + u*(15 + u*(6 + u))), with no cancellation. I'll send both separately.Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code. I found the bug by scanning
stats/base/distsforexp(...) - 1.@stdlib-js/reviewers