<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 27, 2016 at 9:34 AM Karl via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On 27 Jun 2016, at 16:23, Stephen Canon <<a href="mailto:scanon@apple.com" target="_blank">scanon@apple.com</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div dir="auto"><div>On Jun 25, 2016, at 05:06, Karl via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div>Proposal: <a href="https://gist.github.com/karwa/273db66cd8a5fe2c388ccc7de9c4cf31" target="_blank">https://gist.github.com/karwa/273db66cd8a5fe2c388ccc7de9c4cf31</a></div></blockquote></div></blockquote><div><br></div><div>Karl, thanks for writing this up. It should be extended to include not only floor( ) and ceiling( ), but also:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>/// Returns the integral value closest to `self` whose magnitude is not greater than that of `self`.</div><div><span style="white-space:pre-wrap">        </span>func truncate( ) -> Self</div><div><br></div><div><span style="white-space:pre-wrap">        </span>/// Returns the integral value closest to `self`. If two integrers are equally close, the even one</div><div><span style="white-space:pre-wrap">        </span>/// is returned.</div><div><span style="white-space:pre-wrap">        </span>// NOTE: The name of this function requires bike-shedding. I’ve chosen a deliberately poor</div><div><span style="white-space:pre-wrap">        </span>// name as a straw-man.</div><div><span style="white-space:pre-wrap">        </span>func roundToNearestTiesToEven( ) -> Self</div><div><br></div><div><div><span style="white-space:pre-wrap">        </span>/// Returns the integral value closest to `self`. If two integrers are equally close, the one with</div><div><span style="white-space:pre-wrap">        </span>/// greater magnitude is returned.</div><div><span style="white-space:pre-wrap">        </span>// NOTE: The name of this function requires bike-shedding. I’ve chosen a deliberately poor</div><div><span style="white-space:pre-wrap">        </span>// name as a straw-man.</div></div><div><span style="white-space:pre-wrap">        </span>func roundToNearestTiesAway( ) -> Self</div><div><br></div><div>and mutating versions of those.</div><div><br></div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><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></div></div></div></blockquote><div><br></div><div>(-4.5).truncate == -4</div><div>(-4.5).roundedDown == -5</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div></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></div><div>enum FloatingPointRoundingStrategy { // or something to that effect</div><div> case preferEven</div><div> case preferGreatest</div><div>}</div><div><br></div><div>func rounded(inTiebreak: FloatingPointRoundingStrategy) -> Self</div><div><br></div><div>I think `(4.5).rounded(inTiebreak: .preferGreatest) == 5.0` looks quite nice.</div></div></div><div style="word-wrap:break-word"><br><div>Karl</div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>