[swift-evolution] Implicit truncation

Jaden Geller jaden.geller at gmail.com
Sun May 21 18:29:22 CDT 2017


This is an excellent point. I’d very much support an `Int(truncating:)` and an `Int(rounding:)` initializer from Float.

Cheers,
Jaden Geller

> On May 21, 2017, at 1:30 PM, Rudolf Adamkovič via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hi,
> 
> I just wanted to ask why there’s no “truncating” label when converting say Float to Int:
> 
> let foo: Float = 1.9
> let bar = Int(foo)
> 
> I do Swift tutoring on the side and the fact that “bar” equals to 1 always surprises my students.
> 
> From the Swift API Guidelines:
> 
>> In “narrowing” type conversions, though, a label that describes the narrowing is recommended.
> 
> So, why there’s no “truncating” label in this case?
> 
> Thanks!
> 
> R+
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list