[swift-evolution] Implicit truncation

Xiaodi Wu xiaodi.wu at gmail.com
Mon May 22 09:09:07 CDT 2017

Let'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)`.
On Mon, May 22, 2017 at 08:06 Rudolf Adamkovič <salutis at me.com> wrote:

> > On 22 May 2017, at 14:18, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> >
> > What are the "subtle bugs all over the place" that you observe, and what
> did those users expect to happen?
> They pretty much universally expect the value to be rounded. When this
> happens, I tell them about this language called C (… insert long story here
> ...) and we replace "Int(foo)" with "foo.rounded()”. We write a unit test
> and move on. So far, so good. However, two weeks later, they do it again.
> And again. If the initializer said “truncating” or something along those
> lines, I’m sure they wouldn’t pick that one. They are all smart people,
> it’s just that there’s absolutely no “visible clue” and they don’t expect
> this to be the default behavior.
> P.S. I haven’t followed the “integer protocols” debate and had no idea
> that “this issue is settled” and that it "cannot go back”. Also, I have no
> time nor interest to "bikeshed endlessly”. I just wanted to share
> real-world experience/observation with smart people in here (like you) to
> improve the language going forward.
> Thank you!
> R+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170522/16f0eed0/attachment.html>

More information about the swift-evolution mailing list