用法一
multipliedFullWidth(by:)
聲明
func multipliedFullWidth(by other: Int64) -> (high: Int64, low: Int64.Magnitude)
返回值
一個元組,包含將此值與 other
相乘的結果的高位和低位部分。
參數
other
將此值乘以的值。
詳述
使用此方法計算否則會溢出的產品的完整結果。與傳統的截斷乘法不同,multipliedFullWidth(by:)
方法返回一個元組,其中包含該值與 other
乘積的 high
和 low
部分。以下示例使用此方法將兩個在相乘時通常會溢出的 UInt8
值相乘:
let x: UInt8 = 100
let y: UInt8 = 20
let result = x.multipliedFullWidth(by: y)
// result.high == 0b00000111
// result.low == 0b11010000
x
和 y
的乘積是 2000,它太大而無法在 UInt8
實例中表示。 result
值的high
和low
屬性在連接形成double-width 整數時表示2000;也就是說,使用result.high
作為高字節,result.low
作為UInt16
實例的低字節。
let z = UInt16(result.high) << 8 | UInt16(result.low)
// z == 2000
可用版本
用法二
multipliedFullWidth(by:)
聲明
func multipliedFullWidth(by other: Self) -> (high: Self, low: Self.Magnitude)
返回值
一個元組,包含將此值與 other
相乘的結果的高位和低位部分。
參數
other
將此值乘以的值。
詳述
使用此方法計算否則會溢出的產品的完整結果。與傳統的截斷乘法不同,multipliedFullWidth(by:)
方法返回一個元組,其中包含該值與 other
乘積的 high
和 low
部分。以下示例使用此方法將兩個在相乘時通常會溢出的 Int8
值相乘:
let x: Int8 = 48
let y: Int8 = -40
let result = x.multipliedFullWidth(by: y)
// result.high == -8
// result.low == 128
x
和 y
的乘積是 -1920
,它太大而無法在 Int8
實例中表示。 result
值的 high
和 low
組件在連接形成 double-width 整數時表示 -1920
;也就是說,使用result.high
作為高字節,result.low
作為Int16
實例的低字節。
let z = Int16(result.high) << 8 | Int16(result.low)
// z == -1920
可用版本
相關用法
- Swift Int64 magnitude用法及代碼示例
- Swift Int64 -(_:)用法及代碼示例
- Swift Int64 leadingZeroBitCount用法及代碼示例
- Swift Int64 quotientAndRemainder(dividingBy:)用法及代碼示例
- Swift Int64 !=(_:_:)用法及代碼示例
- Swift Int64 &=(_:_:)用法及代碼示例
- Swift Int64 nonzeroBitCount用法及代碼示例
- Swift Int64 -=(_:_:)用法及代碼示例
- Swift Int64 ~(_:)用法及代碼示例
- Swift Int64 <<(_:_:)用法及代碼示例
- Swift Int64 init(integerLiteral:)用法及代碼示例
- Swift Int64 -(_:_:)用法及代碼示例
- Swift Int64 trailingZeroBitCount用法及代碼示例
- Swift Int64 ...(_:)用法及代碼示例
- Swift Int64 init(truncatingIfNeeded:)用法及代碼示例
- Swift Int64 %(_:_:)用法及代碼示例
- Swift Int64 &-(_:_:)用法及代碼示例
- Swift Int64 ..<(_:_:)用法及代碼示例
- Swift Int64 /(_:_:)用法及代碼示例
- Swift Int64 /=(_:_:)用法及代碼示例
- Swift Int64 init(_:)用法及代碼示例
- Swift Int64 ^(_:_:)用法及代碼示例
- Swift Int64 &*(_:_:)用法及代碼示例
- Swift Int64 &+=(_:_:)用法及代碼示例
- Swift Int64 random(in:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Int64 multipliedFullWidth(by:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。