Instance Method

quotientAndRemainder(dividingBy:)

Returns the quotient and remainder of this value divided by the given value.

Declaration

func quotientAndRemainder(dividingBy rhs: Int) -> (quotient: Int, remainder: Int)

Parameters

rhs

The value to divide this value by.

Return Value

A tuple containing the quotient and remainder of this value divided by rhs.

Discussion

Use this method to calculate the quotient and remainder of a division at the same time.

let x = 1_000_000
let (q, r) = x.quotientAndRemainder(dividingBy: 933)
// q == 1071
// r == 757

See Also

Performing Calculations

Integer Operators

Perform arithmetic and bitwise operations or compare values.

func negate()

Replaces this value with its additive inverse.

func isMultiple(of: Int) -> Bool

Returns true if this value is a multiple of the given value, and false otherwise.