Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12765] BinaryFloatingPoint.random(in:) cannot produce all values in range #55210

Open
NevinBR opened this issue May 9, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@NevinBR
Copy link
Contributor

NevinBR commented May 9, 2020

Previous ID SR-12765
Radar None
Original Reporter @NevinBR
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: a098fd3f86f235d183201c32511e97cf

Issue Description:

The random methods on BinaryFloatingPoint are documented with:

/// The `random(in:using:)` static method chooses a random value from a
/// continuous uniform distribution in `range`, and then converts that value
/// to the nearest representable value in this type.

However, the current implementation chooses randomly among 2ⁿ evenly-spaced values in the range, where n is one more than the significand bit-count.

For ranges that span several binades, this coarse-grained comb will miss many representable values in the range.

Furthermore, it will also trap on very large ranges (SR-8798) and it will trap on types where significandBitCount == RawSignificand.bitWidth.

I have written a replacement implementation that solves all of these issues, however I have never contributed significant code to the Swift project before and I would appreciate guidance on how to proceed.

@NevinBR
Copy link
Contributor Author

NevinBR commented May 9, 2020

Tagging @stephentyrone

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant