<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 &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><br class=""></div><div>Karl, thanks for writing this up. &nbsp;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&nbsp;truncate( ) -&gt; Self</div><div><br class=""></div><div><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><span class="Apple-tab-span" style="white-space:pre">        </span>///&nbsp;is returned.</div><div><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><span class="Apple-tab-span" style="white-space:pre">        </span>//&nbsp;&nbsp;name as a straw-man.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func&nbsp;roundToNearestTiesToEven( ) -&gt; 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`. &nbsp;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>// &nbsp;NOTE: The name of this function requires bike-shedding. &nbsp;I’ve chosen a deliberately poor</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>//&nbsp;&nbsp;name as a straw-man.</div></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func&nbsp;roundToNearestTiesAway( ) -&gt; 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. &nbsp;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) -&gt; 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). &nbsp;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>