<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. 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=""> static var min: Self { get }</div><div class=""> 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<Self> { 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: RangeDiscoverable {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>static let representableRange: Range<Int> = Int.min…Int.max</div><div class="">}</div></div><div class=""><br class=""></div><div class="">extension Float: RangeDiscoverable {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// not sure it would be better to use -Float. greatestFiniteMagnitude..Float. greatestFiniteMagnitude here or not</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static let representableRange: Range<Float> = -Float.infinity...Float.infinity</div><div class="">}</div><div class=""><br class=""></div><div class="">This would require numeric types to conform to ForwardIndexType. Integer types already conform to RandomAccessIndexType. 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=""> public func predecessor() -> Float {</div><div class=""> return nextafterf(self, Float.min)</div><div class=""> }</div><div class=""> public func successor() -> Float {</div><div class=""> return nextafterf(self, Float.max)</div><div class=""> }</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=""> public func predecessor() -> Float {</div><div class=""> return nextDown</div><div class=""> }</div><div class=""> public func successor() -> Float {</div><div class=""> return nextUp</div><div class=""> }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">What is your thought on adding a protocol similar to RangeDiscoverable (conformed to by all numeric types) and the supporting BidirectionalIndexType conformance for floating point types? 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 <<a href="mailto:scanon@apple.com" class="">scanon@apple.com</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=""><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. 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). 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=""> </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=""> </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>/// Compares greater than all finite numbers.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <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=""> <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=""> </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=""> </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </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=""> </span>/// infinity.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <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=""> <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=""> </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=""> </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>/// Compares less than or equal to all positive normal numbers. 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=""> </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=""> </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=""> <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=""> <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=""> </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=""> </span>///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </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=""> </span>/// zero. 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=""> </span>/// `leastNormalMagnitude`; otherwise they are equal.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <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 <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>> 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. 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. <br class=""><br class="">Integer types have static min / max properties, but floating point types currently do not. The Darwin implementation is very straightforward. <br class=""><br class="">import Darwin<br class=""><br class="">public extension Float {<br class=""> static let min = -FLT_MAX<br class=""> static let max = FLT_MAX<br class="">}<br class=""><br class="">public extension Double {<br class=""> static let min = -DBL_MAX<br class=""> static let max = DBL_MAX<br class="">}<br class=""><br class="">Is there interest in adding this? 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>