<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 22 May 2017, at 15:51, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">If we're to speak of intuition for new developers who've never used a programming language, who are falling back to what they know about mathematics, then quite literally a decimal point _is_ about division by ten.</div></div></div></div></div></blockquote><div><br class=""></div><div>I don't think this necessarily follows; the issue here is that the constructor isn't explicit enough that it is simply lopping off the fractional part. My own experience of maths as taught in school, to go from a decimal to an integer I would expect to round, so I think it's reasonable that Swift should be clear. While it is reflected in the documentation, a good choice of label would allow it to be explicit at the point of use, without requiring a look up each time there is uncertainty.</div><div><br class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><span class="gmail-m_1469358765824769812Apple-tab-span" style="font-family: Monaco; white-space: pre-wrap;">        </span><span style="font-family: Monaco;" class="">func init(truncating:Float) { … }</span></div></div></blockquote><div class=""><br class=""></div><div class="">Again, this particular naming suggestion has been discussed as part of the review of integer protocols and not adopted. The rationale was that the term "truncating" is intended to be left for bit patterns only. The term in Swift is exclusively "rounded toward zero."<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>As I understand it truncation is a term of art from C at least (rounding toward zero is the trunc function I believe?), it also makes sense given that what's happening is that the fractional part is being discarded, regardless of how how high it may be. init(roundTowardZero:Float) seems like it would be very unwieldy by comparison just because truncating is arbitrarily reserved for bit operations.</div><div><br class=""></div><div>Also, when it comes down to it, discarding the fractional part of a float <b class="">is</b> a bit-pattern operation of a sort, as the conversion is simplistically taking the significand, dropping it into an Int then shifting by the exponent.</div><div><br class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><font face="Monaco" class=""><span class="gmail-m_1469358765824769812Apple-tab-span" style="white-space:pre-wrap">        </span>func init(rounding:Float, _ strategy: <wbr class="">FloatingPointRoundingRule) { … }</font></div></div></blockquote><div class=""><br class=""></div><div class="">Again, here, as an addition to the API, this fails the six criteria of Ben Cohen, as it is strictly duplicative of `T(value.rounded(strategy))`.</div></div></div></div></blockquote><br class=""></div><div>Maybe, but init(rounding:) is explicit that something is being done to the value, at which point there's no obvious harm in clarifying what (or allowing full freedom). While avoiding redundancy is good as a general rule, it doesn't mean there can't be any at all if there's some benefit to it; in this case clarity of exactly what kind of rounding is taking place to the Float/Double value.</div></body></html>