protocol
SignedInteger
Inheritance |
BitwiseOperations, Comparable, CustomStringConvertible, Equatable, ExpressibleByIntegerLiteral, Hashable, Integer, IntegerArithmetic, SignedNumber, Strideable, _Incrementable, _Integer, _IntegerArithmetic, _SignedInteger
View Protocol Hierarchy →
|
---|---|
Associated Types |
A type that can represent the distance between two values of 2 inherited items hidden. (Show all) |
Import |
|
Initializers
Convert from Swift's widest signed integer type, trapping on overflow.
Declaration
init
(
_
:
IntMax
)
Declared In
SignedInteger
, _SignedInteger
Create an instance initialized to value
.
Declaration
init
(
integerLiteral
value
:
Self
.
IntegerLiteralType
)
Declared In
ExpressibleByIntegerLiteral
1 inherited item hidden. (Show all)
Static Variables
The empty bitset.
The allZeros
static property is the identity element for bitwise OR
and XOR operations and the fixed point for bitwise AND operations.
For example:
let
x
:
UInt8
=
5
// 0b00000101
// Identity
x
| .
allZeros
// 0b00000101
x
^ .
allZeros
// 0b00000101
// Fixed point
x
&
.
allZeros
// 0b00000000
Declaration
static
var
allZeros
:
Self
{
get
}
Declared In
BitwiseOperations
1 inherited item hidden. (Show all)
Instance Variables
A textual representation of this instance.
Instead of accessing this property directly, convert an instance of any
type to a string by using the String(describing:)
initializer. For
example:
struct
Point
:
CustomStringConvertible
{
let
x
:
Int
,
y
:
Int
var
description
:
String
{
return
"(\(
x
), \(
y
))"
}
}
let
p
=
Point
(
x
:
21
,
y
:
30
)
let
s
=
String
(
describing
:
p
)
(
s
)
// Prints "(21, 30)"
The conversion of p
to a string in the assignment to s
uses the
Point
type's description
property.
Declaration
var
description
:
String
{
get
}
Declared In
CustomStringConvertible
2 inherited items hidden. (Show all)
Static Methods
Adds lhs
and rhs
, returning the result and a Bool
that is
true
iff the operation caused an arithmetic overflow.
Declaration
static
func
addWithOverflow
(
_
lhs
:
Self
,
_
rhs
:
Self
) -
>
(
Self
,
overflow
:
Bool
)
Declared In
_IntegerArithmetic
Divides lhs
and rhs
, returning the result and a Bool
that is
true
iff the operation caused an arithmetic overflow.
Declaration
static
func
divideWithOverflow
(
_
lhs
:
Self
,
_
rhs
:
Self
) -
>
(
Self
,
overflow
:
Bool
)
Declared In
_IntegerArithmetic
Multiplies lhs
and rhs
, returning the result and a Bool
that is
true
iff the operation caused an arithmetic overflow.
Declaration
static
func
multiplyWithOverflow
(
_
lhs
:
Self
,
_
rhs
:
Self
) -
>
(
Self
,
overflow
:
Bool
)
Declared In
_IntegerArithmetic
Divides lhs
and rhs
, returning the remainder and a Bool
that is
true
iff the operation caused an arithmetic overflow.
Declaration
static
func
remainderWithOverflow
(
_
lhs
:
Self
,
_
rhs
:
Self
) -
>
(
Self
,
overflow
:
Bool
)
Declared In
_IntegerArithmetic
Subtracts lhs
and rhs
, returning the result and a Bool
that is
true
iff the operation caused an arithmetic overflow.
Declaration
static
func
subtractWithOverflow
(
_
lhs
:
Self
,
_
rhs
:
Self
) -
>
(
Self
,
overflow
:
Bool
)
Declared In
_IntegerArithmetic
5 inherited items hidden. (Show all)
Instance Methods
Divides lhs
and rhs
, returning the remainder and trapping in case of
arithmetic overflow (except in -Ounchecked builds).
Declaration
func
%(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
IntegerArithmetic
Returns the intersection of bits set in the two arguments.
The bitwise AND operator (&
) returns a value that has each bit set to
1
where both of its arguments had that bit set to 1
. This is
equivalent to the intersection of two sets. For example:
Performing a bitwise AND operation with a value and allZeros
always
returns allZeros
.
(
x
&
.
allZeros
)
// 0b00000000
// Prints "0"
Complexity: O(1).
Declaration
func
&
(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
BitwiseOperations
Multiplies lhs
and rhs
, returning the result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).
Declaration
func
*(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
IntegerArithmetic
Adds lhs
and rhs
, returning the result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).
Declaration
func
+(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
IntegerArithmetic
Divides lhs
and rhs
, returning the result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).
Declaration
func
/(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
IntegerArithmetic
Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.
This function is the only requirement of the Comparable
protocol. The
remainder of the relational operator functions are implemented by the
standard library for any type that conforms to Comparable
.
Parameters: lhs: A value to compare. rhs: Another value to compare.
Declaration
func
<
(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Comparable
Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.
Parameters: lhs: A value to compare. rhs: Another value to compare.
Declaration
func
<
=(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Comparable
Returns a Boolean value indicating whether two values are equal.
Equality is the inverse of inequality. For any values a
and b
,
a == b
implies that a != b
is false
.
Parameters: lhs: A value to compare. rhs: Another value to compare.
Declaration
func
==(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Equatable
Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.
Parameters: lhs: A value to compare. rhs: Another value to compare.
Declaration
func
>
(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Comparable
Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.
Parameters: lhs: A value to compare. rhs: Another value to compare.
Declaration
func
>
=(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Comparable
Returns the bits that are set in exactly one of the two arguments.
The bitwise XOR operator (^
), or exclusive OR operator, returns a value
that has each bit set to 1
where one or the other but not both of
its operators has that bit set to 1
. This is equivalent to the
symmetric difference of two sets. For example:
Performing a bitwise XOR with a value and allZeros
always returns the
same value:
(
x
^ .
allZeros
)
// 0b00000101
// Prints "5"
Complexity: O(1).
Declaration
func
^(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
BitwiseOperations
Returns the union of bits set in the two arguments.
The bitwise OR operator (|
) returns a value that has each bit set to
1
where one or both of its arguments had that bit set to 1
. For
example:
Performing a bitwise OR operation with a value and allZeros
always
returns the same value.
(
x
| .
allZeros
)
// 0b00000101
// Prints "5"
Complexity: O(1).
Declaration
func
|(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
BitwiseOperations
Returns the inverse of the bits set in the argument.
The bitwise NOT operator (~
) is a prefix operator that returns a value
in which all the bits of its argument are flipped: Bits that are 1
in the
argument are 0
in the result, and bits that are 0
in the argument
are 1
in the result. This is equivalent to the inverse of a set. For
example:
let
x
:
UInt8
=
5
// 0b00000101
let
notX
= ~
x
// 0b11111010
Performing a bitwise NOT operation on allZeros
returns a value with
every bit set to 1
.
let
allOnes
= ~
UInt8.allZeros
// 0b11111111
Complexity: O(1).
Declaration
prefix
func
~(
x
:
Self
) -
>
Self
Declared In
BitwiseOperations
Returns the result of negating x
.
Declaration
prefix
func
-(
x
:
Self
) -
>
Self
Declared In
SignedNumber
Subtracts lhs
and rhs
, returning the result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).
Declaration
func
-(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
IntegerArithmetic
, SignedNumber
Returns a Self
x
such that self.distance(to: x)
approximates n
.
If Stride
conforms to Integer
, then self.distance(to: x) == n
.
Complexity: O(1).
Declaration
func
advanced
(
by
n
:
Self
.
Stride
) -
>
Self
Declared In
Strideable
Returns a stride x
such that self.advanced(by: x)
approximates
other
.
If Stride
conforms to Integer
, then self.advanced(by: x) == other
.
Complexity: O(1).
Declaration
func
distance
(
to
other
:
Self
) -
>
Self
.
Stride
Declared In
Strideable
Represent this number using Swift's widest native signed integer type.
Declaration
func
toIntMax
() -
>
IntMax
Declared In
SignedInteger
, IntegerArithmetic
, _SignedInteger
17 inherited items hidden. (Show all)
Default Implementations
Declaration
func
advanced
(
by
n
:
Int
) -
>
Self
Declaration
func
distance
(
to
other
:
Self
) -
>
Int
A set of common requirements for Swift's signed integer types.