Instance Methodswift 6.0.1Swift
multipliedFullWidth(by:)
Returns a tuple containing the high and low parts of the result of multiplying this value by the given value.
func multipliedFullWidth(by other: Int8) -> (high: Int8, low: Int8.Magnitude)
Parameters
- other
The value to multiply this value by.
Returns
A tuple containing the high and low parts of the result of multiplying this value and other
.
Use this method to calculate the full result of a product that would otherwise overflow. Unlike traditional truncating multiplication, the multipliedFullWidth(by:)
method returns a tuple containing both the high
and low
parts of the product of this value and other
. The following example uses this method to multiply two UInt8
values that normally overflow when multiplied:
let x: UInt8 = 100
let y: UInt8 = 20
let result = x.multipliedFullWidth(by: y)
// result.high == 0b00000111
// result.low == 0b11010000
The product of x
and y
is 2000, which is too large to represent in a UInt8
instance. The high
and low
properties of the result
value represent 2000 when concatenated to form a double-width integer; that is, using result.high
as the high byte and result.low
as the low byte of a UInt16
instance.
let z = UInt16(result.high) << 8 | UInt16(result.low)
// z == 2000
Other members in extension
Types
struct SIMD16Storage
Storage for a vector of 16 integers.
struct SIMD2Storage
Storage for a vector of two integers.
struct SIMD32Storage
Storage for a vector of 32 integers.
struct SIMD4Storage
Storage for a vector of four integers.
struct SIMD64Storage
Storage for a vector of 64 integers.
struct SIMD8Storage
Storage for a vector of eight integers.
struct Words
A type that represents the words of this integer.
Typealiases
typealias IntegerLiteralType
A type that represents an integer literal.
typealias Magnitude
A type that can represent the absolute value of any possible value of this type.
typealias SIMDMaskScalar
Type members
init(Double
) Creates an integer from the given floating-point value, rounding toward zero.
init(Float
) Creates an integer from the given floating-point value, rounding toward zero.
init(Float16
) Creates an integer from the given floating-point value, rounding toward zero.
init(bitPattern: UInt8
) Creates a new instance with the same memory representation as the given value.
init?(exactly: Double
) Creates an integer from the given floating-point value, if it can be represented exactly.
init?(exactly: Float
) Creates an integer from the given floating-point value, if it can be represented exactly.
init?(exactly: Float16
) Creates an integer from the given floating-point value, if it can be represented exactly.
init(from: any Decoder
) throws static var bitWidth: Int
The number of bits used for the underlying binary representation of values of this type.
static func != (lhs: Int8, rhs: Int8
) -> Bool static func % (lhs: Int8, rhs: Int8
) -> Int8 static func %= (lhs: inout Int8, rhs: Int8
) static func & (lhs: Int8, rhs: Int8
) -> Int8 static func &<< (lhs: Int8, rhs: Int8
) -> Int8 static func &<<= (lhs: inout Int8, rhs: Int8
) static func &= (lhs: inout Int8, rhs: Int8
) static func &>> (lhs: Int8, rhs: Int8
) -> Int8 static func &>>= (lhs: inout Int8, rhs: Int8
) static func * (lhs: Int8, rhs: Int8
) -> Int8 Multiplies two values and produces their product.
static func *= (lhs: inout Int8, rhs: Int8
) Multiplies two values and stores the result in the left-hand-side variable.
static func + (lhs: Int8, rhs: Int8
) -> Int8 Adds two values and produces their sum.
static func += (lhs: inout Int8, rhs: Int8
) Adds two values and stores the result in the left-hand-side variable.
static func - (lhs: Int8, rhs: Int8
) -> Int8 Subtracts one value from another and produces their difference.
static func -= (lhs: inout Int8, rhs: Int8
) Subtracts the second value from the first and stores the difference in the left-hand-side variable.
static func / (lhs: Int8, rhs: Int8
) -> Int8 static func /= (lhs: inout Int8, rhs: Int8
) static func < (lhs: Int8, rhs: Int8
) -> Bool static func <= (lhs: Int8, rhs: Int8
) -> Bool static func == (lhs: Int8, rhs: Int8
) -> Bool static func > (lhs: Int8, rhs: Int8
) -> Bool static func >= (lhs: Int8, rhs: Int8
) -> Bool static func ^ (lhs: Int8, rhs: Int8
) -> Int8 static func ^= (lhs: inout Int8, rhs: Int8
) static func | (lhs: Int8, rhs: Int8
) -> Int8 static func |= (lhs: inout Int8, rhs: Int8
)
Instance members
var byteSwapped: Int8
var customMirror: Mirror
A mirror that reflects the
Int8
instance.var leadingZeroBitCount: Int
The number of leading zeros in this value’s binary representation.
var magnitude: UInt8
var nonzeroBitCount: Int
var trailingZeroBitCount: Int
The number of trailing zeros in this value’s binary representation.
var words: Int8.Words
func addingReportingOverflow(Int8
) -> (partialValue: Int8, overflow: Bool) func dividedReportingOverflow(by: Int8
) -> (partialValue: Int8, overflow: Bool) func dividingFullWidth((high: Int8, low: Int8.Magnitude)
) -> (quotient: Int8, remainder: Int8) Returns a tuple containing the quotient and remainder of dividing the given value by this value.
func encode(to: any Encoder
) throws Encodes this value into the given encoder.
func hash(into: inout Hasher
) Hashes the essential components of this value by feeding them into the given hasher.
func multipliedReportingOverflow(by: Int8
) -> (partialValue: Int8, overflow: Bool) func remainderReportingOverflow(dividingBy: Int8
) -> (partialValue: Int8, overflow: Bool) func signum(
) -> Int8 func subtractingReportingOverflow(Int8
) -> (partialValue: Int8, overflow: Bool)
Show obsolete interfaces (1)
Hide obsolete interfaces
var customPlaygroundQuickLook: _PlaygroundQuickLook
A custom playground Quick Look for the
Int8
instance.