[swift-evolution] Implicit truncation
Martin R
martinr448 at gmail.com
Wed May 24 01:55:56 CDT 2017
> On 24. May 2017, at 04:34, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>
> Yes. First, the Foundation initializer converting from NSNumber has the same behavior:
>
> ```
> import Foundation
> let x = Int(42.5 as NSNumber) // x == 42
> ```
As of SE-170 (which is implemented in Swift 4), the label "truncating" is also used for conversions which loose precision:
let x = Int(42.5 as NSNumber) // // warning: 'init' is deprecated
let y = Int(truncating: 42.5 as NSNumber) // 42
let z = Int(exactly: 42.5 as NSNumber) // nil
Regards ,Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170524/49d17c40/attachment.html>
More information about the swift-evolution
mailing list