Skip to content

Commit

Permalink
Fix shift constant in UInt _resigned
Browse files Browse the repository at this point in the history
Assigned a constant unless the architecture is unknown.
  • Loading branch information
nvzqz committed Mar 7, 2017
1 parent 5c7cfcb commit 52311c2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Sources/RandomKit/Extensions/Swift/Integer+RandomKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,15 @@ extension UInt: UnsafeRandom, RandomWithMax, RandomWithMin, RandomToValue, Rando
}

fileprivate var _resigned: UInt {
let msb: UInt
if MemoryLayout<Int>.size == 8 {
msb = 1 << 63
} else {
msb = 1 << 31
}
return self ^ msb
let bits: UInt
#if arch(i386) || arch(arm)
bits = 31
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
bits = 63
#else
bits = UInt(bitPattern: MemoryLayout<UInt>.size * 8 - 1)
#endif
return self ^ (1 << bits)
}

}
Expand Down

0 comments on commit 52311c2

Please sign in to comment.