實例方法
dividing
dividingFullWidth(_:)
返回一個元組,其中包含通過將給定值除以該值獲得的商和餘數。
必需的。
聲明
func dividingFullWidth(_ dividend: (high: Self, low: Self.Magnitude)) -> (quotient: Self, remainder: Self)
返回值
包含通過將dividend
除以該值獲得的商和餘數的元組。
參數
dividend
包含 double-width 整數的高位和低位部分的元組。
詳述
結果商必須在類型的範圍內是可表示的。如果商太大而無法在類型中表示,則可能會發生運行時錯誤。
以下示例將一個太大而無法使用單個 Int
實例表示的值除以另一個 Int
值。因為商可以表示為 Int
,所以除法成功。
// 'dividend' represents the value 0x506f70652053616e74612049494949
let dividend = (22640526660490081, 7959093232766896457 as UInt)
let divisor = 2241543570477705381
let (quotient, remainder) = divisor.dividingFullWidth(dividend)
// quotient == 186319822866995413
// remainder == 0
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift FixedWidthInteger &-=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &<<=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &<<(_:_:)用法及代碼示例
- Swift FixedWidthInteger multipliedFullWidth(by:)用法及代碼示例
- Swift FixedWidthInteger &-(_:_:)用法及代碼示例
- Swift FixedWidthInteger &*=(_:_:)用法及代碼示例
- Swift FixedWidthInteger nonzeroBitCount用法及代碼示例
- Swift FixedWidthInteger init(_:radix:)用法及代碼示例
- Swift FixedWidthInteger random(in:)用法及代碼示例
- Swift FixedWidthInteger &>>=(_:_:)用法及代碼示例
- Swift FixedWidthInteger leadingZeroBitCount用法及代碼示例
- Swift FixedWidthInteger &>>(_:_:)用法及代碼示例
- Swift FixedWidthInteger random(in:using:)用法及代碼示例
- Swift FixedWidthInteger &+=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &*(_:_:)用法及代碼示例
- Swift FixedWidthInteger &+(_:_:)用法及代碼示例
- Swift FixedWidthInteger用法及代碼示例
- Swift FlattenSequence prefix(_:)用法及代碼示例
- Swift Float -(_:)用法及代碼示例
- Swift FlattenSequence max(by:)用法及代碼示例
- Swift Float80 /(_:_:)用法及代碼示例
- Swift Float ...(_:_:)用法及代碼示例
- Swift FloatingPointRoundingRule.toNearestOrAwayFromZero用法及代碼示例
- Swift Float16 ...(_:_:)用法及代碼示例
- Swift FloatingPointRoundingRule.up用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 FixedWidthInteger dividingFullWidth(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。