<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 <<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=""><br class=""><blockquote type="cite" class=""><div dir="auto" class=""><div class="">On Jun 25, 2016, at 05:06, Karl via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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: <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. 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 truncate( ) -> 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`. If two integrers are equally close, the even one</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// is returned.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// NOTE: The name of this function requires bike-shedding. I’ve chosen a deliberately poor</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// name as a straw-man.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func roundToNearestTiesToEven( ) -> 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`. 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>// NOTE: The name of this function requires bike-shedding. I’ve chosen a deliberately poor</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>// name as a straw-man.</div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func roundToNearestTiesAway( ) -> 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 { // or something to that effect</div><div> case preferEven</div><div> case preferGreatest</div><div>}</div><div><br class=""></div><div>func rounded(inTiebreak: FloatingPointRoundingStrategy) -> 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>