<div dir="ltr">On Mon, May 22, 2017 at 9:30 AM, Haravikk <span dir="ltr">&lt;<a href="mailto:swift-evolution@haravikk.me" target="_blank">swift-evolution@haravikk.me</a>&gt;</span> wrote:<br><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"><span class="gmail-"><br><div><blockquote type="cite"><div>On 22 May 2017, at 15:09, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="gmail-m_1469358765824769812Apple-interchange-newline"><div>Let&#39;s be clear: it _is_ rounded, just toward zero. It is consistent with the behavior of integer division. I would guess that your students also repeatedly struggle with the result that `2 / 3 == 0`? If so, they have not been taught some important fundamentals of integer arithmetic. If not, then it should be natural that `Int(2 / 3 as Double == Int(2 / 3 as UInt)`.</div></blockquote></div><br></span><div>Just to add my thoughts; but while I agree that it&#39;s important developers learn the intricacies of Int vs. Float, I don&#39;t think this is quite the same issue as divisions.</div><div><br></div><div>If you&#39;re asking for an Int then you should have some idea that you&#39;re asking for a whole number only, and so that follows on to division as Ints simply cannot handle fractions.</div><div><br></div><div>However, for conversion from Float there&#39;s an expectation that some rounding must occur, the problem is that it&#39;s not as expected; while you or I would expect it to be this way with familiarity of other languages, for someone new to the language this isn&#39;t always going to be the case. While it&#39;s reasonable to expect new developers to know what an Int is, I think it&#39;s unreasonable for them also to remember what the default rounding strategy of an implicitly rounding constructor is.</div></div></blockquote><div><br></div><div>It&#39;s _not_ an arbitrarily chosen default rounding strategy to be remembered. I mean, if you want to memorize it and move on, then of course that&#39;s fine. But at heart it goes to what a decimal point is. Let&#39;s go back to grade school. What does it mean to write &quot;1.9&quot;? Well, it means &quot;one whole thing and nine parts out of ten of a thing,&quot; or in other words, &quot;1 + 9/10&quot; or &quot;19 / 10&quot;.  Now, what happens in Swift?</div><div><br></div><div>```</div><div>let x = Int(19 / 10) // x == 1</div><div>let y = Int(1 + 9 / 10) // y == 1</div><div>let z = Int(1.9) // z == 1</div><div>```</div><div><br></div><div>If we&#39;re to speak of intuition for new developers who&#39;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><br></div><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"><div>For this reason I tend to agree with the principle that the Int(_:Float) constructor should probably be labelled more intuitively, personally I&#39;d like to see:</div><div><br></div><div><font face="Monaco"><span class="gmail-m_1469358765824769812Apple-tab-span" style="white-space:pre-wrap">        </span>func init(truncating:Float) { … }</font></div></div></blockquote><div><br></div><div>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 &quot;truncating&quot; is intended to be left for bit patterns only. The term in Swift is exclusively &quot;rounded toward zero.&quot;<br></div><div> </div><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"><div><font face="Monaco"><span class="gmail-m_1469358765824769812Apple-tab-span" style="white-space:pre-wrap">        </span>func init(rounding:Float, _ strategy: <wbr>FloatingPointRoundingRule) { … }</font></div></div></blockquote><div><br></div><div>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><br></div><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"><div>Here the init(truncating:) constructor is just a convenience form of init(rounding:) with a strategy of .towardZero, which I believe is consistent with the current behaviour. It&#39;s also easily swapped in anywhere that init(_:Float) etc. are currently used.</div></div></blockquote></div><br></div><div class="gmail_extra"><br></div></div>