[swift-evolution] Implicit truncation

Guillaume Lessard glessard at tffenterprises.com
Wed May 24 00:00:16 CDT 2017


> On May 23, 2017, at 20:34, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> On Tue, May 23, 2017 at 5:27 PM, Guillaume Lessard via swift-evolution <swift-evolution at swift.org> wrote:
> 
> > Is there another lossy initializer for Int or BinaryInteger that doesn’t have a parameter label?
> 
> Yes. First, the Foundation initializer converting from NSNumber has the same behavior:
> 
> ```
> import Foundation
> let x = Int(42.5 as NSNumber) // x == 42
> ```

That’s basically a repetition that brought no additional information to the table. The question stands.


> Now, you might argue that trapping does not meet your definition of "lossy," but it certainly causes problems in the example posed above:

I’m not talking about trapping, I’m talking about losing information. As in, the reverse conversion may differ from the original value. (why do you make me define this?). Trapping is fine; it’s the right behaviour.

More broadly, though, I and others would like to know why it’s *better* to have no label on Int.init(_ x: Float) than to have one. Your attitude seems to be that the status quo needs no justification, but perhaps the status quo is not a global optimum.

Sincerely,
Guillaume Lessard



More information about the swift-evolution mailing list