protocol
SignedIntegerType
Inheritance |
BidirectionalIndexType, BitwiseOperationsType, Comparable, CustomStringConvertible, Equatable, ForwardIndexType, Hashable, IntegerArithmeticType, IntegerLiteralConvertible, IntegerType, RandomAccessIndexType, SignedNumberType, Strideable, _Incrementable, _IntegerArithmeticType, _IntegerType, _RandomAccessAmbiguity, _SignedIntegerType
View Protocol Hierarchy →
|
---|---|
Associated Types |
A type that can represent the number of steps between pairs of
Reachability is defined by the ability to produce one value from
the other via zero or more applications of
A type that can represent the distance between two values of 3 inherited items hidden. (Show all) |
Import |
|
Initializers
Convert from Swift's widest signed integer type, trapping on overflow.
Declaration
init
(
_
:
IntMax
)
Declared In
SignedIntegerType
, _SignedIntegerType
Create an instance initialized to value
.
Declaration
init
(
integerLiteral
value
:
Self
.
IntegerLiteralType
)
Declared In
IntegerLiteralConvertible
1 inherited item hidden. (Show all)
Static Variables
The empty bitset.
Also the identity element for |
and
^
, and the fixed point for
&
.
Declaration
static
var
allZeros
:
Self
{
get
}
Declared In
BitwiseOperationsType
1 inherited item hidden. (Show all)
Instance Variables
A textual representation of self
.
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
_IntegerArithmeticType
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
_IntegerArithmeticType
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
_IntegerArithmeticType
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
_IntegerArithmeticType
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
_IntegerArithmeticType
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
IntegerArithmeticType
Returns the intersection of bits set in lhs
and rhs
.
Complexity: O(1).
Declaration
func
&
(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
BitwiseOperationsType
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
IntegerArithmeticType
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
IntegerArithmeticType
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
IntegerArithmeticType
A strict total order
over instances of Self
.
Declaration
func
<
(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Comparable
Returns true
if lhs
is equal to rhs
.
Equality implies substitutability. When x == y
, x
and
y
are interchangeable in any code that only depends on their
values.
Class instance identity as distinguished by triple-equals ===
is notably not part of an instance's value. Exposing other
non-value aspects of Equatable
types is discouraged, and any
that are exposed should be explicitly pointed out in
documentation.
Equality is an equivalence relation
x == x
istrue
x == y
impliesy == x
x == y
andy == z
impliesx == z
Inequality is the inverse of equality, i.e. !(x == y)
iff
x != y
.
Declaration
func
==(
lhs
:
Self
,
rhs
:
Self
) -
>
Bool
Declared In
Equatable
Returns the bits that are set in exactly one of lhs
and rhs
.
Complexity: O(1).
Declaration
func
^(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
BitwiseOperationsType
Returns the union of bits set in lhs
and rhs
.
Complexity: O(1).
Declaration
func
|(
lhs
:
Self
,
rhs
:
Self
) -
>
Self
Declared In
BitwiseOperationsType
Returns x ^ ~Self.allZeros
.
Complexity: O(1).
Declaration
prefix
func
~(
x
:
Self
) -
>
Self
Declared In
BitwiseOperationsType
Returns the result of negating x
.
Declaration
prefix
func
-(
x
:
Self
) -
>
Self
Declared In
SignedNumberType
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
IntegerArithmeticType
, SignedNumberType
Returns the result of advancing self
by n
positions.
Returns:
- If n > 0
, the result of applying successor
to self
n
times.
- If n < 0
, the result of applying predecessor
to self
-n
times.
- Otherwise, self
.
Requires: n >= 0
if only conforming to ForwardIndexType
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(abs(n)
) otherwise
Declaration
func
advancedBy
(
n
:
Self
.
Distance
) -
>
Self
Declared In
ForwardIndexType
, RandomAccessIndexType
, Strideable
Returns the result of advancing self
by n
positions, or until it
equals limit
.
Returns:
- If n > 0
, the result of applying successor
to self
n
times
but not past limit
.
- If n < 0
, the result of applying predecessor
to self
-n
times
but not past limit
.
- Otherwise, self
.
Requires: n >= 0
if only conforming to ForwardIndexType
.
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(abs(n)
) otherwise
Declaration
func
advancedBy
(
n
:
Self
.
Distance
,
limit
:
Self
) -
>
Self
Declared In
ForwardIndexType
, RandomAccessIndexType
Measure the distance between self
and end
.
Requires:
- start
and end
are part of the same sequence when conforming to
RandomAccessSequenceType
.
- end
is reachable from self
by incrementation otherwise.
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(n
) otherwise, where n
is the function's result.
Declaration
func
distanceTo
(
end
:
Self
) -
>
Self
.
Distance
Declared In
ForwardIndexType
, RandomAccessIndexType
, Strideable
Returns the previous consecutive value in a discrete sequence.
If self
has a well-defined successor,
self.successor().predecessor() == self
. If self
has a
well-defined predecessor, self.predecessor().successor() ==
self
.
Requires: self
has a well-defined predecessor.
Declaration
func
predecessor
() -
>
Self
Declared In
BidirectionalIndexType
Returns the next consecutive value in a discrete sequence of
Self
values.
Requires: self
has a well-defined successor.
Declaration
func
successor
() -
>
Self
Declared In
_Incrementable
Represent this number using Swift's widest native signed integer type.
Declaration
func
toIntMax
() -
>
IntMax
Declared In
SignedIntegerType
, IntegerArithmeticType
, _SignedIntegerType
20 inherited items hidden. (Show all)
Default Implementations
Returns the result of advancing self
by n
positions.
Returns:
- If n > 0
, the result of applying successor
to self
n
times.
- If n < 0
, the result of applying predecessor
to self
-n
times.
- Otherwise, self
.
Requires: n >= 0
if only conforming to ForwardIndexType
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(abs(n)
) otherwise
Declaration
func
advancedBy
(
n
:
Self
.
Distance
) -
>
Self
Declared In
IntegerType
, RandomAccessIndexType
, BidirectionalIndexType
, _RandomAccessAmbiguity
, ForwardIndexType
Returns the result of advancing self
by n
positions, or until it
equals limit
.
Returns:
- If n > 0
, the result of applying successor
to self
n
times
but not past limit
.
- If n < 0
, the result of applying predecessor
to self
-n
times
but not past limit
.
- Otherwise, self
.
Requires: n >= 0
if only conforming to ForwardIndexType
.
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(abs(n)
) otherwise
Declaration
func
advancedBy
(
n
:
Self
.
Distance
,
limit
:
Self
) -
>
Self
Declared In
IntegerType
, RandomAccessIndexType
, BidirectionalIndexType
, ForwardIndexType
Measure the distance between self
and end
.
Requires:
- start
and end
are part of the same sequence when conforming to
RandomAccessSequenceType
.
- end
is reachable from self
by incrementation otherwise.
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(n
) otherwise, where n
is the function's result.
Declaration
func
distanceTo
(
end
:
Self
) -
>
Self
.
Distance
Declared In
IntegerType
, RandomAccessIndexType
, BidirectionalIndexType
, ForwardIndexType
Returns the sequence of values (self
, self + stride
, self +
stride + stride
, ... last) where last is the last value in
the progression less than or equal to end
.
Note: There is no guarantee that end
is an element of the sequence.
Declaration
func
stride
(
through
end
:
Self
,
by
stride
:
Self
.
Stride
) -
>
StrideThrough
<
Self
>
Declared In
IntegerType
, RandomAccessIndexType
, Strideable
Returns the sequence of values (self
, self + stride
, self +
stride + stride
, ... last) where last is the last value in
the progression that is less than end
.
Declaration
func
stride
(
to
end
:
Self
,
by
stride
:
Self
.
Stride
) -
>
StrideTo
<
Self
>
Declared In
IntegerType
, RandomAccessIndexType
, Strideable
5 inherited items hidden. (Show all)
A set of common requirements for Swift's signed integer types.