isMultiple(of:)
Returns true
if this value is a multiple of the given value, and false
otherwise.
Available because
Self
conforms toSignedInteger
.Available when
Self
conforms toFixedWidthInteger
func isMultiple(of other: Self) -> Bool
Parameters
- other
The value to test.
Overview
For two integers a and b, a is a multiple of b if there exists a third integer q such that a = q*b. For example, 6 is a multiple of 3 because 6 = 2*3. Zero is a multiple of everything because 0 = 0*x for any integer x.
Two edge cases are worth particular attention:
x.isMultiple(of: 0)
istrue
ifx
is zero andfalse
otherwise.T.min.isMultiple(of: -1)
istrue
for signed integerT
, even though the quotientT.min / -1
isn’t representable in typeT
.