swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-8798] BinaryFloatingPoint.random(in:) crashes on some valid ranges

Open hartbit opened this issue 7 years ago • 3 comments

Previous ID SR-8798
Radar None
Original Reporter @hartbit
Type Bug

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

md5: e4ed61953fff624b3e51c4a4dfb662dd

Issue Description:

The following piece of code crashes at runtime:

extension BinaryFloatingPoint where Self.RawSignificand: FixedWidthInteger {
    static func random() -> Self {
        return random(in: -greatestFiniteMagnitude..<greatestFiniteMagnitude)
    }
} 

Because of https://github.com/apple/swift/blob/cffe3869a678c62a5d9369fe90a07905cd1d6f07/stdlib/public/core/FloatingPoint.swift.gyb#L2440

This should be fixed.

hartbit avatar Sep 19 '18 12:09 hartbit

cc @stephentyrone, @Azoy

belkadan avatar Sep 19 '18 17:09 belkadan

Yes, this is a known limitation of the algorithm that is currently in use; we're planning to fix it in 5.0.

stephentyrone avatar Sep 20 '18 17:09 stephentyrone

@stephentyrone, is there a plan to fix it in 6.0?

dmitriykotenko avatar Jul 11 '24 20:07 dmitriykotenko

I came here to report this exact issue. Sad to see it's been known for 6 years and still hasn't had any proper attention.

I just want a random finite float lol

KyNorthstar avatar Nov 24 '24 06:11 KyNorthstar