<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=""><div><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><br class=""></div><div>Karl, thanks for writing this up. It should be extended to include not only floor( ) and ceiling( ), but also:</div><div><br class=""></div><div><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><span class="Apple-tab-span" style="white-space:pre">        </span>func truncate( ) -> Self</div><div><br class=""></div><div><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><span class="Apple-tab-span" style="white-space:pre">        </span>/// is returned.</div><div><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><span class="Apple-tab-span" style="white-space:pre">        </span>// name as a straw-man.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func roundToNearestTiesToEven( ) -> Self</div><div><br class=""></div><div><div><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><span class="Apple-tab-span" style="white-space:pre">        </span>/// greater magnitude is returned.</div><div><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><span class="Apple-tab-span" style="white-space: pre;">        </span>// name as a straw-man.</div></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func roundToNearestTiesAway( ) -> Self</div><div><br class=""></div><div>and mutating versions of those.</div><div><br class=""></div><div>Some collected responses to other comments on this thread:</div><div><br class=""></div></div><blockquote type="cite" class=""><div>David Sweeris wrote:</div></blockquote><div><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class=""><div dir="auto" class=""><div class="">The only thing I'm worried about is the situation where we have "x = N.M", and `x.ceiling` equals maybe "(N+2).0" instead of "(N+1).0" because we ran out of precision and can't represent (N+1).0. I'm not sure what the exact values are where floats (or doubles) stop having enough precision to represent inter-integer values... It might be a moot point.</div></div></blockquote><br class=""></div><div>This never happens. Floor and ceiling are always exact operations.</div><div><br class=""></div><div><blockquote type="cite" class="">Austin Rathe wrote:</blockquote><blockquote type="cite" class=""><br class=""></blockquote></div><div><blockquote type="cite" class=""><span class="Apple-tab-span" style="font-family: Monaco; white-space: pre;">        </span><span style="font-family: Monaco;" class="">func roundedUp(withPrecision:Int) -> Self { … }</span></blockquote><br class=""></div><div>While I understand where you’re going with this, you can’t round non-decimal floating-point numbers to a non-zero number of decimal digits (the result won’t be representable, in general). This should be available for decimal floating-point types if/when they are added, but should be handled as part of conversions to String for binary floating-point types.</div><div><br class=""></div><div>– Steve</div></body></html>