Skip to content

Commit 2612e00

Browse files
committed
Additional notes from @xwu
1 parent 2f9bf3c commit 2612e00

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

stdlib/public/core/Integers.swift.gyb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,7 +3234,7 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
32343234
} else {
32353235
// At this point we know source's bitWidth > Base.bitWidth, or else
32363236
// we would've taken the first branch.
3237-
let lowInT = source & T(~Low(0))
3237+
let lowInT = source & T(~0 as Low)
32383238
let highInT = source &>> numericCast(High.bitWidth)
32393239

32403240
let low = Low(lowInT.magnitude)
@@ -3281,7 +3281,7 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
32813281
// FIXME: spurious compile error when 'where' clause above is removed:
32823282
// error: non-nominal type 'T.RawSignificand' does not support explicit initialization
32833283
let fractionPart: Raw = bitPattern &<< Raw(Raw.bitWidth - offset)
3284-
guard fractionPart == 0 else {
3284+
guard fractionPart == (0 as Raw) else {
32853285
return nil
32863286
}
32873287

@@ -3374,7 +3374,7 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
33743374
let result = DoubleWidth(extendingOrTruncating: product)
33753375

33763376
let isNegative = (self < (0 as DoubleWidth)) != (rhs < (0 as DoubleWidth))
3377-
let didCarry = isNegative ? carry != ~0 : carry != 0
3377+
let didCarry = isNegative ? carry != ~(0 as DoubleWidth) : carry != (0 as DoubleWidth)
33783378
let hadPositiveOverflow = !isNegative &&
33793379
DoubleWidth.isSigned && product.leadingZeroBitCount == 0
33803380

@@ -3406,7 +3406,7 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
34063406
let highBit = ~(~0 >> 1) as Magnitude
34073407
for _ in initialOffset..<DoubleWidth.bitWidth {
34083408
r <<= 1
3409-
if q & highBit != 0 {
3409+
if q & highBit != (0 as Magnitude) {
34103410
r += 1 as Magnitude
34113411
}
34123412
q <<= 1
@@ -3431,7 +3431,9 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
34313431

34323432
public func dividedReportingOverflow(by other: DoubleWidth)
34333433
-> (partialValue: DoubleWidth, overflow: ArithmeticOverflow) {
3434-
if other == 0 || (DoubleWidth.isSigned && other == -1 && self == .min) {
3434+
if other == (0 as DoubleWidth) ||
3435+
(DoubleWidth.isSigned && other == (-1 as Int) && self == .min)
3436+
{
34353437
return (self, .overflow)
34363438
}
34373439

@@ -3440,7 +3442,9 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
34403442

34413443
public func remainderReportingOverflow(dividingBy other: DoubleWidth)
34423444
-> (partialValue: DoubleWidth, overflow: ArithmeticOverflow) {
3443-
if other == 0 || (DoubleWidth.isSigned && other == -1 && self == .min) {
3445+
if other == 0 ||
3446+
(DoubleWidth.isSigned && other == -1 && self == .min)
3447+
{
34443448
return (self, .overflow)
34453449
}
34463450

@@ -3460,8 +3464,8 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
34603464
func sum(_ x: Low, _ y: Low, _ z: Low) -> (partial: Low, carry: Low) {
34613465
let (sum1, overflow1) = x.addingReportingOverflow(y)
34623466
let (sum2, overflow2) = sum1.addingReportingOverflow(z)
3463-
let carry: Low = (overflow1 == .overflow ? Low(1) : Low(0))
3464-
+ (overflow2 == .overflow ? Low(1) : Low(0))
3467+
let carry: Low = (overflow1 == .overflow ? 1 : 0) +
3468+
(overflow2 == .overflow ? 1 : 0)
34653469
return (sum2, carry)
34663470
}
34673471

@@ -3535,7 +3539,9 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
35353539
}
35363540

35373541
// Shift is larger than this type's bit width.
3538-
if rhs._storage.high != 0 || rhs._storage.low >= DoubleWidth.bitWidth {
3542+
if rhs._storage.high != (0 as High) ||
3543+
rhs._storage.low >= DoubleWidth.bitWidth
3544+
{
35393545
lhs = lhs < (0 as DoubleWidth) ? ~0 : 0
35403546
return
35413547
}
@@ -3616,13 +3622,13 @@ public struct DoubleWidth<Base : FixedWidthInteger> :
36163622
}
36173623

36183624
public var leadingZeroBitCount: Int {
3619-
return high == 0
3625+
return high == (0 as High)
36203626
? Base.bitWidth + low.leadingZeroBitCount
36213627
: high.leadingZeroBitCount
36223628
}
36233629

36243630
public var trailingZeroBitCount: Int {
3625-
return low == 0
3631+
return low == (0 as Low)
36263632
? Base.bitWidth + high.trailingZeroBitCount
36273633
: low.trailingZeroBitCount
36283634
}

0 commit comments

Comments
 (0)