Repository navigation
Conversation
Evaluate exp(-x*x/2) directly with the split-square helper instead of taking sqrt(exp(-x*x)). The old intermediate underflowed early, losing accuracy near -27 and returning zero at -30 even though the normal CDF is representable. Add an optional half-exponent specialization while retaining the existing expx2 behavior for other callers. Use a coarser exact-square split for float tails. Propagate NaN inputs while preserving infinite endpoints. Cover float, double, and extended-real tails with independent high-precision references, including a subnormal double result. Document the platform exponential and subnormal accuracy limits. AI-Assisted-By: Codex (GPT-6 Astra Medium)
Standardize finite opposite-signed observations by dividing before subtraction when x - mean overflows. Preserve the ordinary subtraction path for normal PDF and CDF calls. Include small standard deviations in the exponent when the unscaled density is subnormal or zero, so scaling can recover a representable PDF. For inverse CDFs, halve the finite terms before combining an overflowing scaled quantile with its location. Retain endpoint infinities and existing arithmetic outside the recovery paths. Add float, double, and real regressions for extreme locations, subnormal scales, and finite quantiles after cancellation. AI-Assisted-By: Codex (GPT-6 Astra Medium)
Use the requested floating-point type for the final sqrt(2*pi) multiplier when it has more precision than double. The unconditional double cast discarded precision after evaluating the central polynomial in real. Preserve the existing float and double arithmetic. Add independent first- and third-quartile references on platforms with extended real precision. AI-Assisted-By: Codex (GPT-6 Astra Medium)
Correct the integral's normalization to 1/sqrt(2*pi), consistent with its exp(-t*t/2) integrand. Explain that small upper-tail probabilities should be evaluated as normalCDF(-x), rather than lost by subtracting a rounded CDF from one. AI-Assisted-By: Codex (GPT-6 Astra Medium)
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.
Normal distribution functions can lose representable results when intermediate calculations overflow or underflow. This PR corrects those cases in mir.math.func.normal while preserving public signatures and ordinary calculation paths where possible.
Changes
Validation
Added float, double, and real regressions using independent high-precision references, including subnormal tails, extreme locations, tiny scales, inverse endpoints, and extended-precision quartiles.
Full DMD and LDC suites passed during development. Final optimized focused tests passed with both compilers.
The recovery checks introduce measurable overhead on some scaled paths; ordinary formulas and rounding are retained outside the exceptional cases.
These fixes also underpin the local normal implementations in libmir/mir-stat#159. This PR independently benefits callers using mir.math.func.normal.
AI-Assisted-By: Codex (GPT-6 Astra Medium)