Skip to content

Fix Uniform::new_inclusive overflow on large finite float ranges - #1821

Open
dhardy wants to merge 6 commits into
masterfrom
push-zwrtyxtlykum
Open

Fix Uniform::new_inclusive overflow on large finite float ranges#1821
dhardy wants to merge 6 commits into
masterfrom
push-zwrtyxtlykum

Conversation

@dhardy

@dhardy dhardy commented Aug 5, 2026

Copy link
Copy Markdown
Member
  • Added a CHANGELOG.md entry

Summary

Replaces #1809, allowing Uniform::new_inclusive to accept ranges like 0.0..=f64::MAX which overflow-to-infinity, without extra code.

Details

This allows UniformFloat::new_inclusive(0.0, f64::MAX) to return a valid sampler, though in practice the largest value which may be sampled remains 1.next_down() * MAX = MAX.next_down().

This is slightly more consistent with sample_single_inclusive which also accepts this range and also does not actually ever emit the largest value.

teddytennant and others added 6 commits July 11, 2026 13:25
Dividing high - low by 1 - EPSILON can round to infinity even when the
range itself is finite (e.g. 0.0..=f64::MAX), yielding a spurious
NonFinite error while Uniform::new and sample_single_inclusive both
accept the same range. Clamp infinite lanes to the largest finite value
and let new_bounded reduce scale as usual, so that samples still cannot
exceed high.

Noted by dhardy in #1603.
@dhardy
dhardy requested a review from vks August 5, 2026 08:15
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.

2 participants