[swift-users] Where to report this bug?

Shawn Erickson shawnce at gmail.com
Fri Sep 22 13:28:51 CDT 2017


The bug is about the compiler reporting a compile error for a function that
purposely is designed to allow for overflow and handling of said overflow.
It should be allowed to be used in all scopes in code. It seems like the
compiler is able to reason and prove overflow will happen in certain code
scopes (but not all) resulting in a compile time error (which is nice)
however it is doing this with a stdlib function that is meant to deal with
overflow so it should in theory be allowed.

On Fri, Sep 22, 2017 at 8:41 AM Claude Pommerell via swift-users <
swift-users at swift.org> wrote:

> This is not a bug. The error reports correctly that -Int.min cannot be
> represented in the Int type. This holds true for all implementations of
> fixed-size signed integers in Swift and most languages. In fact, Int.min is
> defined as Int.min = -Int.max-1.
>
> The reason is that almost all fixed-sized implementations of signed
> integers can represent an even number of integers. Since zero is both
> positive and negative, they cannot represent an equal number of positive
> and negative numbers. By convention, there is one more negative number,
> because arithmetics is easier to implement electronically this way.
>
> Zero is represented in binary by 000…000, -1 by 111…111, Int.max by
> 011…111, and Int.min by 100…000. The first bit can be interpreted as a sign
> bit, it is 0 for all positive numbers, and 1 for all non-positive (that is,
> smaller than zero) numbers. You can negate all numbers by inverting all of
> their bits and than adding 1, ignoring the overflow to the unrepresentable
> 1000…000 when passing from -1 to 0, and signalling an overflow when
> inverting Int.min. All additions can be implemented as if the binary
> representations were unsigned, checking for overflow only if both terms
> have the same sign.
>
> On 22 Sep 2017, at 03:42, Peter W A Wood via swift-users <
> swift-users at swift.org> wrote:
>
> Entering the following statement in a playground gives an overflow error.
> Where should I report this?
>
> Statement:
>
> Int.min.dividedReportingOverflow(by:-1)
>
> Playground log:
>
> *Playground execution failed:*
>
> *error: MyPlayground.playground:3:9: error: division '-9223372036854775808
> / -1' results in an overflow*
> *Int.min.dividedReportingOverflow(by:-1)*
>
> Peter
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170922/d6d27678/attachment.html>


More information about the swift-users mailing list