[swift-users] Where to report this bug?

Claude Pommerell cp at valuefromsoftware.com
Fri Sep 22 02:52:15 CDT 2017

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170922/7a53b39b/attachment.html>

More information about the swift-users mailing list