> On Mar 30, 2016, at 12:57 PM, Ted F.A. van Gaalen via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> Thank you, Robert & Haravikk
> Please allow me to respond in-line hereunder, thanks.
> Ted.
>> On 30.03.2016, at 16:15, Haravikk <swift-evolut...@haravikk.me 
>> <mailto:swift-evolut...@haravikk.me>> wrote:
>> 
>> I’m in favour of implicit conversion for integers where no data can be lost 
>> (UInt32 to Int64, Int32 to Int64 etc.), in fact I posted a similar thread a 
>> little while ago but can’t find it; there’s something being done with 
>> numbers so this may be partly in the works.
>> 
>> I definitely think that implicit conversion for floating point should be 
>> avoided, as it can’t be guaranteed
> Why?  and   What cannot be guaranteed? 


These all fail with a runtime error ("Playground execution aborted: Execution 
was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, 
subcode=0x0)”, if you’re curious):
Int(Double.infinity)
Int(Double.NaN)
Int(Double.quietNaN)

And this loop runs for 1024 iterations before finding just one instance where 
the conversion from Int to Double and back to Int actually gives the right 
answer:
var i = UInt(Int.max) + 1
var remainder = UInt()
repeat {
    i -= 1
    let DoubleI = UInt(Double(i))
    remainder = DoubleI > i ? DoubleI - i : i - DoubleI
} while remainder != 0

- Dave Sweeris
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to