I've changed my mind about BinaryInteger/isZero. It's common enough to deserves a seat among isInfinite and isNegative. Even integers with unknown signedness can implement it, so DataInt/isZero makes sense too. A binary integer extension can also ensure that big integers perform the operation in place, which is preferred for performance reasons.
extension BinaryInteger {
/// Indicates whether this value is equal to zero.
///
/// - Note: Big integers evaluate it in place, cf. `compared(to: 0)`.
///
@inlinable public var isZero: Bool {
if !Self.size.isInfinite {
return self == Self.zero
} else {
return self.withUnsafeBinaryIntegerElements {
$0.isZero
}
}
}
}
I've changed my mind about BinaryInteger/isZero. It's common enough to deserves a seat among isInfinite and isNegative. Even integers with unknown signedness can implement it, so DataInt/isZero makes sense too. A binary integer extension can also ensure that big integers perform the operation in place, which is preferred for performance reasons.