<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Today, one can get <font face="Menlo" style="font-size: 11px;" class="">max</font>/<font face="Menlo" style="font-size: 11px;" class="">min</font> by doing:<div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">let max = Float.greatestFiniteMagnitude</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">let min = -Float.greatestFiniteMagnitude</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class="">I propose that the floating point types expose properties for <font face="Menlo" style="font-size: 11px;" class="">max</font>/<font face="Menlo" style="font-size: 11px;" class="">min</font>.</div><div class=""><br class=""></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">max</font>, in particular, is used quite a lot in UI code for fixed-width layout of text. But having to spell out <font face="Menlo" style="font-size: 11px;" class="">greatestFiniteMagnitude</font> every time is a pain. For example…</div><div class=""><br class=""></div><div class="">Compare this:</div><div class=""><font face="Menlo" style="font-size: 11px;" class="">extension NSTextView {<br class=""> func configureForFixedWidth() {<br class=""> minSize = NSSize.zero<br class=""> maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)<br class=""> isHorizontallyResizable = false<br class=""> isVerticallyResizable = true<br class=""><br class=""> textContainer?.containerSize = NSSize(width: bounds.width, height: CGFloat.greatestFiniteMagnitude)<br class=""> textContainer?.widthTracksTextView = true<br class=""> }<br class="">}</font></div><div class=""><font class=""><br class=""></font></div><div class="">To this:</div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">extension </span><span style="font-family: Menlo; font-size: 11px;" class="">NSTextView</span><span style="font-family: Menlo; font-size: 11px;" class=""> {</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">func</span><span style="font-family: Menlo; font-size: 11px;" class=""> configureForFixedWidth() {</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">minSize</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="font-family: Menlo; font-size: 11px;" class="">NSSize</span><span style="font-family: Menlo; font-size: 11px;" class="">.zero</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">maxSize</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="font-family: Menlo; font-size: 11px;" class="">NSSize</span><span style="font-family: Menlo; font-size: 11px;" class="">(width: CGFloat.max</span><span style="font-family: Menlo; font-size: 11px;" class="">, height:</span><span style="font-family: Menlo; font-size: 11px;" class=""> CGFloat.max</span><span style="font-family: Menlo; font-size: 11px;" class="">)</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">isHorizontallyResizable</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="font-family: Menlo; font-size: 11px;" class="">false</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">isVerticallyResizable</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="font-family: Menlo; font-size: 11px;" class="">true</span><br style="font-family: Menlo; font-size: 11px;" class=""><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">textContainer</span><span style="font-family: Menlo; font-size: 11px;" class="">?.</span><span style="font-family: Menlo; font-size: 11px;" class="">containerSize</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="font-family: Menlo; font-size: 11px;" class="">NSSize</span><span style="font-family: Menlo; font-size: 11px;" class="">(width: </span><span style="font-family: Menlo; font-size: 11px;" class="">bounds</span><span style="font-family: Menlo; font-size: 11px;" class="">.</span><span style="font-family: Menlo; font-size: 11px;" class="">width</span><span style="font-family: Menlo; font-size: 11px;" class="">, height:</span><span style="font-family: Menlo; font-size: 11px;" class=""> CGFloat.max</span><span style="font-family: Menlo; font-size: 11px;" class="">)</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">textContainer</span><span style="font-family: Menlo; font-size: 11px;" class="">?.</span><span style="font-family: Menlo; font-size: 11px;" class="">widthTracksTextView</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="font-family: Menlo; font-size: 11px;" class="">true</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">}</span><br style="font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Menlo; font-size: 11px;" class="">}</span></div><div class=""><br class=""></div><div class="">The latter snippet is much more understandable (and less typing). It is more understandable because users don’t have to know exactly how floating point works in order to get the equivalent of <font face="Menlo" style="font-size: 11px;" class="">Int.max</font>/<font face="Menlo" style="font-size: 11px;" class="">Int.min</font> for <font face="Menlo" style="font-size: 11px;" class="">CGFloat</font>.</div><div class=""><br class=""></div><div class="">One of the concerns with naming them <font face="Menlo" style="font-size: 11px;" class="">max</font>/<font face="Menlo" style="font-size: 11px;" class="">min</font> is that <font face="Menlo" style="font-size: 11px;" class="">infinity</font>/<font face="Menlo" style="font-size: 11px;" class="">-infinity</font> is technically the real max/min. We could name them <font face="Menlo" style="font-size: 11px;" class="">finiteMax</font>/<font face="Menlo" style="font-size: 11px;" class="">finiteMin</font>, but I think keeping the names consistent with <font face="Menlo" style="font-size: 11px;" class="">Int</font> et al. is important since they serve the same purpose. Besides, I think dealing with <font face="Menlo" style="font-size: 11px;" class="">infinity</font> is rare in real-world usage. Those that are using <font face="Menlo" style="font-size: 11px;" class="">infinity</font> know that it is obviously the true max.</div><div class=""><br class=""></div><div class="">I think adding these floating point properties is in line with Swift 3’s goals of consistency and refinement.</div><div class=""><br class=""></div><div class="">Thoughts?</div></body></html>