<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 14, 2016, at 4:55 PM, Stephen Canon via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div></blockquote><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="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class="">
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `true` iff the signbit of `self` is set. Implements the IEEE 754</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `signbit` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Note that this is not the same as `self < 0`. In particular, this</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// property is true for `-0` and some NaNs, both of which compare not</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// less than zero.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// TODO: strictly speaking a bit and a bool are slightly different</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// concepts. Is another name more appropriate for this property?</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// `isNegative` is incorrect because of -0 and NaN. `isSignMinus` might</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// be acceptable, but isn't great. `signBit` is the IEEE 754 name.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> signBit: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>(signBit: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>, exponent: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>, significand: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
</pre></div></div></div></blockquote><div>These do feel a bit awkward. Perhaps something over-engineered to handle the typical cases more readably?</div><div><br class=""></div><div><font face="Menlo" class=""> public protocol FloatingPoint: SignedArithmetic, Comparable {</font></div><div><font face="Menlo" class=""> enum Sign { </font></div><div><font face="Menlo" class=""> case Plus</font></div><div><font face="Menlo" class=""> case Minus</font></div><div><font face="Menlo" class=""> init(bit: Bool) { return bit ? .Minus : .Plus }</font></div><div><font face="Menlo" class=""> var bit: Bool { get { return self == Minus } }</font></div><div><font face="Menlo" class=""> }</font></div><div><font face="Menlo" class=""> </font></div><div><font face="Menlo" class=""> var sign: Sign { get }</font></div><div><font face="Menlo" class=""> var signBit: Bool { get }</font></div><div><font face="Menlo" class=""> </font></div><div><font face="Menlo" class=""> init(sign: Sign, exponent: Int, significand: Self)</font></div><div><font face="Menlo" class=""> init(signBit: Bool, exponent: Int, significand: Self)</font></div><div><font face="Menlo" class=""> </font></div><div><font face="Menlo" class=""> …</font></div><div><font face="Menlo" class=""> }</font></div><div><br class=""></div><div>…and perhaps each sign/signBit pair would provides one as a default implementation that calls the other.</div><div><br class=""></div><div>Then we can often write something more readable than signBit: </div><div><br class=""></div><div><font face="Menlo" class=""> let x = Float(sign: .Plus, exponent: 2, signficand: 2)</font></div><div><font face="Menlo" class=""> if x.sign == .Plus { … }</font></div><div><br class=""></div><div>Alternatively or additionally, perhaps signBit ought to be an Int because the people writing code using signBit would probably prefer to use literal 1 and 0 instead of true and false. (Hasn't the distinction between Bit and Bool come up before?)</div><div><br class=""></div><div><br class=""></div><div>-- </div><div>Greg Parker <a href="mailto:gparker@apple.com" class="">gparker@apple.com</a> Runtime Wrangler</div><div><br class=""></div><div><br class=""></div></div></body></html>