Filed as https://bugs.swift.org/browse/SR-5964 <https://bugs.swift.org/browse/SR-5964>
Martin > On 22. Sep 2017, at 12:11, Alex Blewitt <alb...@apple.com> wrote: > > 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 <martinr...@gmail.com >> <mailto:martinr...@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@swift.org <mailto:swift-users@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@swift.org <mailto:swift-users@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@swift.org <mailto:swift-users@swift.org> >>>> https://lists.swift.org/mailman/listinfo/swift-users >>>> <https://lists.swift.org/mailman/listinfo/swift-users> >>> >>> _______________________________________________ >>> swift-users mailing list >>> swift-users@swift.org <mailto:swift-users@swift.org> >>> https://lists.swift.org/mailman/listinfo/swift-users >>> <https://lists.swift.org/mailman/listinfo/swift-users> >> >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users