[swift-evolution] [Proposal] Random Unification

Saagar Jha saagar at saagarjha.com
Wed Jan 10 16:27:47 CST 2018


Not a floating point expert, but are you sure this works? I have a feeling this would lead to a distribution that’s not uniform.

Saagar Jha

> On Jan 10, 2018, at 14:07, Jens Persson via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Tue, Jan 9, 2018 at 10:07 PM, Jonathan Hull via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> One additional question.  How do you ergonomically get a Double which doesn’t have a range, but also isn’t NaN?
> 
> 
> Assuming you are ok with signed zero and infinities and "strange" bias as result of IEEE 754:
> 
> func randomNonNanDouble<R: RandomNumberGenerator>(using generator: R) -> Double {
>     while true {
>         let rndUInt64 = generator.next()
>         let rndDouble = Double(bitPattern: rndUInt64)
>         if rndDouble != Double.nan { return rndDouble }
>     }
> }
> 
> /Jens
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180110/154d1f3a/attachment.html>


More information about the swift-evolution mailing list