[swift-evolution] Add max/min to floating point types

Darren Mo darren.mo at me.com
Sun Jun 12 22:59:36 CDT 2016

> On Jun 12, 2016, at 11:35 PM, Stephen Canon <scanon at apple.com> wrote:
>> On Jun 10, 2016, at 5:20 PM, Darren Mo <darren.mo at me.com <mailto:darren.mo at me.com>> wrote:
>>> – They’re not actually the maximum and minimum values of the type.  In particular, that `max(Float.infinity, .max)` wouldn’t be `Float.max` is pretty seriously confusing.
>> Infinity is a special value. I would argue that people who use infinity know exactly what they are doing and would not be thrown by Float.infinity being greater than Float.max. I am willing to bet that most regular users don’t even know that infinity can be represented since it is rarely needed in real-world usage.
> For clarity, what use cases do you have in mind where the largest finite value is more appropriate than infinity?

That… is a very good question.

My main use case was laying out fixed-width text. In the Objective-C days, I would use CGFLOAT_MAX. I guess when I started to write the same code in Swift, I didn’t stop to think about whether there was a better value. Now thanks to you, I see that CGFloat.infinity is the clearest and most appropriate value.

Proposal cancelled. Thanks! ☺️
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160612/0b2dad73/attachment.html>

More information about the swift-evolution mailing list