<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 27 Jun 2016, at 16:23, 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=""><br class=""><blockquote type="cite" class=""><div dir="auto" class=""><div class="">On Jun 25, 2016, at 05:06, Karl via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class="">Proposal:&nbsp;<a href="https://gist.github.com/karwa/273db66cd8a5fe2c388ccc7de9c4cf31" class="">https://gist.github.com/karwa/273db66cd8a5fe2c388ccc7de9c4cf31</a></div></blockquote></div></blockquote><div class=""><br class=""></div><div class="">Karl, thanks for writing this up. &nbsp;It should be extended to include not only floor( ) and ceiling( ), but also:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Returns the integral value closest to `self` whose magnitude is not greater than that of `self`.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func&nbsp;truncate( ) -&gt; Self</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Returns the integral value closest to `self`. &nbsp;If two integrers are equally close, the even one</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>///&nbsp;is returned.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// &nbsp;NOTE: The name of this function requires bike-shedding. &nbsp;I’ve chosen a deliberately poor</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>//&nbsp;&nbsp;name as a straw-man.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func&nbsp;roundToNearestTiesToEven( ) -&gt; Self</div><div class=""><br class=""></div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>/// Returns the integral value closest to `self`. &nbsp;If two integrers are equally close, the one with</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// greater magnitude is returned.</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>// &nbsp;NOTE: The name of this function requires bike-shedding. &nbsp;I’ve chosen a deliberately poor</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>//&nbsp;&nbsp;name as a straw-man.</div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func&nbsp;roundToNearestTiesAway( ) -&gt; Self</div><div class=""><br class=""></div><div class="">and mutating versions of those.</div><div class=""><br class=""></div></div></div></div></blockquote><div><br class=""></div><div>I was trying to add these, but working out the names of the mutating functions is difficult. How is truncate different to floor if it returns an integral value and can never round up?</div><div><br class=""></div><div>Perhaps for the other functions, we could have a general `round` function with a tiebreak-enum parameter (it would be great if we could embed enums in protocols, but I’m not sure if that’s even on the roadmap):</div><div><br class=""></div><div>enum FloatingPointRoundingStrategy { &nbsp; // or something to that effect</div><div>&nbsp; &nbsp; case preferEven</div><div>&nbsp; &nbsp; case preferGreatest</div><div>}</div><div><br class=""></div><div>func rounded(inTiebreak:&nbsp;FloatingPointRoundingStrategy) -&gt; Self</div><div><br class=""></div><div>I think `(4.5).rounded(inTiebreak: .preferGreatest) == 5.0` looks quite nice.</div></div><br class=""><div class="">Karl</div></body></html>