Required Instance Methodswift 6.0.1Swift
dividingFullWidth(_:)
Returns a tuple containing the quotient and remainder obtained by dividing the given value by this value.
func dividingFullWidth(_ dividend: (high: Self, low: Self.Magnitude)) -> (quotient: Self, remainder: Self)
Parameters
- dividend
A tuple containing the high and low parts of a double-width integer.
Returns
A tuple containing the quotient and remainder obtained by dividing dividend
by this value.
The resulting quotient must be representable within the bounds of the type. If the quotient is too large to represent in the type, a runtime error may occur.
The following example divides a value that is too large to be represented using a single Int
instance by another Int
value. Because the quotient is representable as an Int
, the division succeeds.
// 'dividend' represents the value 0x506f70652053616e74612049494949
let dividend = (22640526660490081, 7959093232766896457 as UInt)
let divisor = 2241543570477705381
let (quotient, remainder) = divisor.dividingFullWidth(dividend)
// quotient == 186319822866995413
// remainder == 0
Other requirements
Type members
init(bigEndian: Self
) Creates an integer from its big-endian representation, changing the byte order if necessary.
init(littleEndian: Self
) Creates an integer from its little-endian representation, changing the byte order if necessary.
static var bitWidth: Int
The number of bits used for the underlying binary representation of values of this type.
static var max: Self
The maximum representable integer in this type.
static var min: Self
The minimum representable integer in this type.
static func &* (lhs: Self, rhs: Self
) -> Self Returns the product of the two given values, wrapping the result in case of any overflow.
static func &<< (lhs: Self, rhs: Self
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.
static func &<<= (lhs: inout Self, rhs: Self
) Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.
static func &>> (lhs: Self, rhs: Self
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width.
static func &>>= (lhs: inout Self, rhs: Self
) Calculates the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.
Instance members
var bigEndian: Self
The big-endian representation of this integer.
var byteSwapped: Self
A representation of this integer with the byte order swapped.
var leadingZeroBitCount: Int
The number of leading zeros in this value’s binary representation.
var littleEndian: Self
The little-endian representation of this integer.
var nonzeroBitCount: Int
The number of bits equal to 1 in this value’s binary representation.
func addingReportingOverflow(Self
) -> (partialValue: Self, overflow: Bool) Returns the sum of this value and the given value, along with a Boolean value indicating whether overflow occurred in the operation.
func dividedReportingOverflow(by: Self
) -> (partialValue: Self, overflow: Bool) Returns the quotient obtained by dividing this value by the given value, along with a Boolean value indicating whether overflow occurred in the operation.
func multipliedFullWidth(by: Self
) -> (high: Self, low: Self.Magnitude) Returns a tuple containing the high and low parts of the result of multiplying this value by the given value.
func multipliedReportingOverflow(by: Self
) -> (partialValue: Self, overflow: Bool) Returns the product of this value and the given value, along with a Boolean value indicating whether overflow occurred in the operation.
func remainderReportingOverflow(dividingBy: Self
) -> (partialValue: Self, overflow: Bool) Returns the remainder after dividing this value by the given value, along with a Boolean value indicating whether overflow occurred during division.
func subtractingReportingOverflow(Self
) -> (partialValue: Self, overflow: Bool) Returns the difference obtained by subtracting the given value from this value, along with a Boolean value indicating whether overflow occurred in the operation.