<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=""><div class="">CGFloat has .max and .min. And if you use them, you get:</div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">2016-06-10 13:32:14.185 Untitled Page 10[18435:13174627] This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on void _NSLayoutConstraintNumberExceedsLimit() to debug. This will be logged only once. This may break in the future.</b></span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""><br class=""></b></span></div><div class="">-- E</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 10, 2016, at 12:24 PM, Darren Mo via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div 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=""></div></div></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div 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></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>