Required Initializerswift 6.0.1Swift
init(clamping:)
Creates a new instance with the representable value that’s closest to the given integer.
init<T>(clamping source: T) where T : BinaryInteger
Parameters
- source
An integer to convert to this type.
If the value passed as source
is greater than the maximum representable value in this type, the result is the type’s max
value. If source
is less than the smallest representable value in this type, the result is the type’s min
value.
In this example, x
is initialized as an Int8
instance by clamping 500
to the range -128...127
, and y
is initialized as a UInt
instance by clamping -500
to the range 0...UInt.max
.
let x = Int8(clamping: 500)
// x == 127
// x == Int8.max
let y = UInt(clamping: -500)
// y == 0
Other requirements
View members
Hide members
This section is hidden by default because it contains too many (33) members.
Type members
associatedtype Words
A type that represents the words of a binary integer.
init<T>(T
) Creates an integer from the given floating-point value, rounding toward zero.
init<T>(T
) Creates a new instance from the given integer.
init?<T>(exactly: T
) Creates an integer from the given floating-point value, if it can be represented exactly.
init<T>(truncatingIfNeeded: T
) Creates a new instance from the bit pattern of the given instance by sign-extending or truncating to fit this type.
static var isSigned: Bool
A Boolean value indicating whether this type is a signed integer type.
static func % (lhs: Self, rhs: Self
) -> Self Returns the remainder of dividing the first value by the second.
static func %= (lhs: inout Self, rhs: Self
) Divides the first value by the second and stores the remainder in the left-hand-side variable.
static func & (lhs: Self, rhs: Self
) -> Self Returns the result of performing a bitwise AND operation on the two given values.
static func &= (lhs: inout Self, rhs: Self
) Stores the result of performing a bitwise AND operation on the two given values in the left-hand-side variable.
static func * (lhs: Self, rhs: Self
) -> Self Multiplies two values and produces their product.
static func *= (lhs: inout Self, rhs: Self
) Multiplies two values and stores the result in the left-hand-side variable.
static func + (lhs: Self, rhs: Self
) -> Self Adds two values and produces their sum.
static func += (lhs: inout Self, rhs: Self
) Adds two values and stores the result in the left-hand-side variable.
static func - (lhs: Self, rhs: Self
) -> Self Subtracts one value from another and produces their difference.
static func -= (lhs: inout Self, rhs: Self
) Subtracts the second value from the first and stores the difference in the left-hand-side variable.
static func / (lhs: Self, rhs: Self
) -> Self Returns the quotient of dividing the first value by the second.
static func /= (lhs: inout Self, rhs: Self
) Divides the first value by the second and stores the quotient in the left-hand-side variable.
static func << <RHS>(lhs: Self, rhs: RHS
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left.
static func <<= <RHS>(lhs: inout Self, rhs: RHS
) Stores the result of shifting a value’s binary representation the specified number of digits to the left in the left-hand-side variable.
static func >> <RHS>(lhs: Self, rhs: RHS
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right.
static func >>= <RHS>(lhs: inout Self, rhs: RHS
) Stores the result of shifting a value’s binary representation the specified number of digits to the right in the left-hand-side variable.
static func ^ (lhs: Self, rhs: Self
) -> Self Returns the result of performing a bitwise XOR operation on the two given values.
static func ^= (lhs: inout Self, rhs: Self
) Stores the result of performing a bitwise XOR operation on the two given values in the left-hand-side variable.
static func | (lhs: Self, rhs: Self
) -> Self Returns the result of performing a bitwise OR operation on the two given values.
static func |= (lhs: inout Self, rhs: Self
) Stores the result of performing a bitwise OR operation on the two given values in the left-hand-side variable.
static func ~ (x: Self
) -> Self Returns the inverse of the bits set in the argument.
Instance members
var bitWidth: Int
The number of bits in the current binary representation of this value.
var trailingZeroBitCount: Int
The number of trailing zeros in this value’s binary representation.
var words: Self.Words
A collection containing the words of this value’s binary representation, in order from the least significant to most significant.
func isMultiple(of: Self
) -> Bool Returns
true
if this value is a multiple of the given value, andfalse
otherwise.func quotientAndRemainder(dividingBy: Self
) -> (quotient: Self, remainder: Self) Returns the quotient and remainder of this value divided by the given value.
func signum(
) -> Self Returns
-1
if this value is negative and1
if it’s positive; otherwise,0
.
Citizens in Swift
Default implementations
init<Other>(clamping: Other
) Creates a new instance with the representable value that’s closest to the given integer.