[swift-users] Where to report this bug?
Alex Blewitt
alblue at apple.com
Fri Sep 22 05:11:32 CDT 2017
Hmm... probably worth filing a bug at https://bugs.swift.org <https://bugs.swift.org/> then with the below test case.
Alex
> On 22 Sep 2017, at 10:14, Martin R <martinr448 at gmail.com> wrote:
>
> But the purpose of
>
> func dividedReportingOverflow(by other: Int <apple-reference-documentation://hsf4N66ABq>) -> (partialValue: Int <apple-reference-documentation://hsf4N66ABq>, overflow: Bool <apple-reference-documentation://hsvynwdxKM>)
>
> is to report an overflow in the return value. And actually this compiles and runs in Xcode 9 if the code is on top-level in main.m:
>
> let minusOne = -1
> let r1 = Int.min.dividedReportingOverflow(by: minusOne)
> print(r1) // (partialValue: -9223372036854775808, overflow: true)
>
> let zero = 0
> let r2 = Int.min.dividedReportingOverflow(by: zero)
> print(r2) // (partialValue: -9223372036854775808, overflow: true)
>
> But the same code inside a function (or do-block) fails to compile:
>
> func foo() {
> let minusOne = -1
> let r1 = Int.min.dividedReportingOverflow(by: minusOne)
> // error: division '-9223372036854775808 / -1' results in an overflow
> print(r1)
>
> let zero = 0
> let r2 = Int.min.dividedReportingOverflow(by: zero)
> // error: division by zero
> print(r2)
> }
>
> Martin
>
>
>> On 22. Sep 2017, at 10:19, Alex Blewitt via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>>
>> Int.min is the smallest negative value, and Int.max is the largest positive value (that fits in an Int). However, the absolute value of Int.min is larger than the absolute value of Int.max. So you can't convert Int.min into -Int.min because it's larger than Int.max.
>>
>> In other words, this is expected behaviour :)
>>
>> For example:
>>
>> Int.min + Int.max = 1
>>
>> If they were the same value, it would be zero.
>>
>> Alex
>>
>>> On 22 Sep 2017, at 02:42, Peter W A Wood via swift-users <swift-users at swift.org <mailto: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 <mailto:swift-users at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
>>
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto: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/eebb917e/attachment.html>
More information about the swift-users
mailing list