<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="">Hi Steve,<div class=""><br class=""></div><div class="">Thanks for looking at my proposal and sharing the internal consensus. &nbsp;I do like the more explicit names.</div><div class=""><br class=""></div><div class="">One of the reasons I proposed this was to follow up with a proposal for a RangeDiscoverable protocol that would be conformed to by all numeric types:</div><div class=""><br class=""></div><div class=""><div class="">protocol RangeDiscoverable {</div><div class="">&nbsp; &nbsp; static var min: Self { get }</div><div class="">&nbsp; &nbsp; static var max: Self { get }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">A better interface would looks like this (not sure why I didn’t think of this before):</div><div class=""><div class=""><br class=""></div><div class="">public protocol RangeDiscoverable {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static var representableRange: Range&lt;Self&gt; { get }</div></div><div class="">}</div><div class=""><br class=""></div><div class="">With conformances that look like this:</div><div class=""><br class=""></div><div class=""><div class="">extension Int:&nbsp;RangeDiscoverable&nbsp;{</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>static let representableRange: Range&lt;Int&gt; = Int.min…Int.max</div><div class="">}</div></div><div class=""><br class=""></div><div class="">extension Float:&nbsp;RangeDiscoverable&nbsp;{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// not sure it would be better to use -Float.&nbsp;greatestFiniteMagnitude..Float.&nbsp;greatestFiniteMagnitude here or not</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static let representableRange: Range&lt;Float&gt; = -Float.infinity...Float.infinity</div><div class="">}</div><div class=""><br class=""></div><div class="">This would require numeric types to conform to ForwardIndexType. &nbsp;Integer types already conform to RandomAccessIndexType. &nbsp;Floating point types do not currently conform to ForwardIndexType but could conform not just to ForwardIndexType, but also BidirectionalIndexType.</div><div class=""><br class=""></div><div class="">My original implementation looked like this:</div><div class=""><br class=""></div><div class=""><div class="">extension Float: BidirectionalIndexType {</div><div class="">&nbsp; &nbsp; public func predecessor() -&gt; Float {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return nextafterf(self, Float.min)</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; public func successor() -&gt; Float {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return nextafterf(self, Float.max)</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">With the nextUp and nextDown properties I see in test/Prototypes/FloatingPoint.swift this could change to:</div><div class=""><br class=""></div><div class=""><div class="">extension Float: BidirectionalIndexType {</div><div class="">&nbsp; &nbsp; public func predecessor() -&gt; Float {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return nextDown</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; public func successor() -&gt; Float {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return nextUp</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">What is your thought on adding a protocol similar to&nbsp;RangeDiscoverable (conformed to by all numeric types) and the supporting BidirectionalIndexType conformance for floating point types? &nbsp;Is this something that would be considered?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 11:41 AM, Stephen Canon &lt;<a href="mailto:scanon@apple.com" class="">scanon@apple.com</a>&gt; 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=""><div class="">Hi Matthew —</div><div class=""><br class=""></div><div class="">This is something that we’ve discussed quite a bit internally, and are close to consensus on. &nbsp;Many people feel that “max” and “min” are confusing or misleading, as they are not actually the largest / smallest values of the type, so the plan is to use much more explicit names (you can see an early sketch of this in test/Prototypes/FloatingPoint.swift, though there are a number of things that will be changed as well). &nbsp;I’ve excerpted the relevant section here for convenience:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// Positive infinity.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// Compares greater than all finite numbers.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> infinity: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Self</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">get</span> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// The greatest finite value.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// Compares greater than or equal to all finite numbers, but less than</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// infinity.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> greatestFiniteMagnitude: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Self</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">get</span> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// The least positive normal value.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// Compares less than or equal to all positive normal numbers.&nbsp; There may</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// be smaller positive numbers, but they are "subnormal", meaning that</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// they are represented with less precision than normal numbers.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> leastNormalMagnitude: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Self</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">get</span> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// The least positive value.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// Compares less than or equal to all positive numbers, but greater than</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// zero.&nbsp; If the target supports subnormal values, this is smaller than</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; </span>/// `leastNormalMagnitude`; otherwise they are equal.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> leastMagnitude: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Self</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">get</span> }</div></div><div class=""><br class=""></div>– Steve<div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 11:10 AM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">In the spirit of small commits and incremental change I have a very small proposal. &nbsp;I am not sure if this belongs on the list or if small changes like this are ok as pull requests, but am starting here because it involves adding public API in the standard library. &nbsp;<br class=""><br class="">Integer types have static min / max properties, but floating point types currently do not. &nbsp;The Darwin implementation is very straightforward. &nbsp;<br class=""><br class="">import Darwin<br class=""><br class="">public extension Float {<br class=""> &nbsp;&nbsp;static let min = -FLT_MAX<br class=""> &nbsp;&nbsp;static let max = FLT_MAX<br class="">}<br class=""><br class="">public extension Double {<br class=""> &nbsp;&nbsp;static let min = -DBL_MAX<br class=""> &nbsp;&nbsp;static let max = DBL_MAX<br class="">}<br class=""><br class="">Is there interest in adding this? &nbsp;If so, what is the right way to proceed?<br class=""><br class="">Matthew<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>