[swift-evolution] Thoughts on clarity of Double and Float type names?

Stephen Canon scanon at apple.com
Tue May 24 08:10:42 CDT 2016


[Charlie, this is more of a reply to the thread than to your message in particular.]

There is absolutely no good reason to have a “word size” floating-point type.  We happen to have one on Apple systems (CGFloat), but that should be viewed as a historical curiosity, not as guidance that it’s a reasonable thing to do.  If we were starting from scratch today, we would not have such a type.

1. Having explicit `Float32`, `Float64`, [`Float16`, `Float128`, … ] type names, by analogy to integer types, is great.

2. Making `Float` and `Double` unavailable in favor of these replacements would be a lot of churn for relatively little value, but it’s not a bad idea if you ignore the one-time pain of conversion.  `Float32` and `Float64` are discoverable enough that this would be OK, IMO.

3.a. Making `Float` a “word size” type is bonkers.  The last thing we want to do is create another type with the same difficulties as `CGFloat`.

3.b. Making `Float` be “the widest HW-supported type” is less bonkers, but still results in gratuitous cross-platform differences and very little real benefit.  We’d also need to be careful about how we defined it, since we would *not* want it to be `Float80` on x86_64 (for performance reasons).

3.c. Making `Float` be an alias of `Float64` would just confuse people coming from a C-family language (as commonly implemented).

– Steve

> On May 24, 2016, at 12:52 AM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
> 
> In UIKit/Cocoa, there's CGFloat that does pretty much what you're asking (and it's pain working with it in Swift, since it's Double on 64-bit computers, while Swift defaults to Float, so you need casting all the time)... And I think the default behavior of Swift should be similar.
> 
> I wouldn't change the type names since Double still is "double precision", I'd just prefer changed default behavior...
> 
> Charlie
> 
>> On May 24, 2016, at 5:39 AM, David Sweeris via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> On May 23, 2016, at 9:55 PM, Xiaodi Wu <xiaodi.wu at gmail.com <mailto:xiaodi.wu at gmail.com>> wrote:
>>> 
>>> On Mon, May 23, 2016 at 9:40 PM, David Sweeris <davesweeris at mac.com <mailto:davesweeris at mac.com>> wrote:
>>> 
>>> Have we (meaning the list in general, not you & me in particular) had this conversation before? This feels familiar...
>>> 
>>> It does, doesn't it? I've been reading this list for too long.
>> I just checked, and we have! In this very thread! I didn’t realize it was started almost 6 months ago…
>> 
>> Out of curiosity, are there plans for Swift's IntegerLiteralType & FloatingPointLiteralType when CPUs eventually support 128-bit ints & floats? Will they still evaluate to “Int64" and “Double” by default, or will they become the bigger types?
>> 
>> - Dave Sweeris
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> 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/20160524/c2c17110/attachment.html>


More information about the swift-evolution mailing list