Skip to content

A few correctness fixes - #7

Merged
astrofrog merged 6 commits into
mainfrom
bug-fixes
Jul 26, 2026
Merged

A few correctness fixes#7
astrofrog merged 6 commits into
mainfrom
bug-fixes

Conversation

@astrofrog

Copy link
Copy Markdown
Owner

This fixes a few bugs:

  • integral_general_subset adds spurious area outside the tabulated range. When the integration limits extend beyond the tabulated x, the routine adds a triangular ramp of area past the domain instead of clamping. Fix: clamp the effective limits to [x(1), x(n)] so out-of-range extremities contribute zero.

  • ipos mishandles both boundaries for descending ranges (xmax < xmin). x == xmin and x == xmax return off-by-one bins. Fix: correct the boundary handling so xmin maps to bin 1 and xmax to bin nbin.

  • xval computes bin centres in single precision. The bin-centre fraction (i - 0.5) / nbin is evaluated in default (single) precision before being used, so the double-precision instantiation loses precision. Fix: compute the fraction in the instantiated kind.

  • sample_pdf_log returns NaN for draws in the first CDF bin. A random value landing in the first bin feeds cdf(1) = 0 into log-log interpolation (log(0)), producing NaN. Fix: use linear interpolation on the CDF axis with boundary guards.

@astrofrog
astrofrog merged commit 8446119 into main Jul 26, 2026
4 checks passed
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