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-8178] BinaryFloatingPoint.random(in range: Range<Self>) can return range.upperBound #50710

Closed
t-ae opened this issue Jul 5, 2018 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@t-ae
Copy link
Contributor

t-ae commented Jul 5, 2018

Previous ID SR-8178
Radar rdar://problem/41851227
Original Reporter @t-ae
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10 beta 3

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee @Azoy
Priority Medium

md5: 83a421c73c3382bd6a76eed3617b3d1c

Issue Description:

BinaryFloatingPoint.random(in range: Range<Self>) can return range.upperBound (obviously out of range) for specific range.

test code:

struct AlwaysMaxRNG: RandomNumberGenerator {
    mutating func next() -> UInt64 {
        return UInt64.max
    }
}

var rng = AlwaysMaxRNG()

print("Float:")
let floatRanges: [Range<Float>] = [0..<1, 1..<2, 2..<4]
for range in floatRanges {
    print("\(range): maximum < upperBound: \(.random(in: range, using: &rng) < range.upperBound)")
}

print("\nDouble:")
let doubleRanges: [Range<Double>] = [0..<1, 1..<2, 2..<4]
for range in doubleRanges {
    print("\(range): maximum < upperBound: \(.random(in: range, using: &rng) < range.upperBound)")
}

output:

Float:
0.0..<1.0: maximum < upperBound: true
1.0..<2.0: maximum < upperBound: false
2.0..<4.0: maximum < upperBound: false

Double:
0.0..<1.0: maximum < upperBound: true
1.0..<2.0: maximum < upperBound: false
2.0..<4.0: maximum < upperBound: false
@belkadan
Copy link
Contributor

belkadan commented Jul 5, 2018

cc @stephentyrone, @moiseev

@stephentyrone
Copy link
Member

Yup, there are a bunch of related issues with this requiring some rework that I'm going to take a look at. This is as good a bug as any for the purpose.

@stephentyrone
Copy link
Member

@swift-ci create.

@stephentyrone
Copy link
Member

[note that this "RNG" is a great test case to add to the test suite while we're at it.]

@Azoy
Copy link
Member

Azoy commented Jul 5, 2018

Oh sorry @stephentyrone, I thought this could have two assignees! I'll try and take a look at this one.

@stephentyrone
Copy link
Member

No worries; if you get to it before me just tag me as a reviewer.

@Azoy
Copy link
Member

Azoy commented Jul 6, 2018

This is resolved in: apple/swift#17794

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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

4 participants