Expand description
Integer numbers, subsets of $\Z$.
An integer (m/w) is a number that can be written without a fractional component.
§Integer subsets
Different integer implementations are classified mathematically by:
- Whether they only have positive sign (
PositiveInteger,NonNegativeInteger), only negative sign (NegativeInteger,NonPositiveInteger), or both (Integer,NonZeroInteger). - Whether they support 0 (
Integer,NonNegativeInteger,NonPositiveInteger) or not (NonZeroInteger,PositiveInteger,NegativeInteger).
This makes for 6 different kinds of integers.
They all implement the Integer trait, and are all variants of the
Integers family enum, which includes also the special Prime kind.
They are also classified computationally, by 6 choices on their bit-size
representation: (8, 16, 32, 64, 128 or Big). Combined makes for
36 choices of integers. (Except Big is only implemented for Integer
for now).
Note that numbers that can represent both positive an negative integers can represent half the max positive or negative value at the same bit-size than their only negative or positive counterparts. E.g.:
assert_eq![[-128, 127], [Integer8::MIN, Integer8::MAX]];
assert_eq![[-255, 255], [NonPositiveInteger8::MIN.into(), NonNegativeInteger8::MAX.into()]];§Operations
Not all types have the same support for arithmetic operations, specially if we want the operation to return an integer of the same type.
We say that a group is closed over an operation when that operation will always return a number of the same type. the following table summarizes the closed operations for each kind of integer:
Integer | NonZero | NonNegative | Positive | Nonpositive | Negative | Prime | |
|---|---|---|---|---|---|---|---|
| sign | + - | + - | + | + | - | - | + |
| zero | 0 | 0 | 0 | ||||
| add | yes | yes | yes | yes | yes | ||
| sub | yes | ||||||
| mul | yes | yes | yes | yes | |||
| div | yes | yes | yes | yes | |||
| rem | yes | yes | yes | ||||
| neg | yes | yes |
Modules§
- n0z
- Non-zero integer numbers (o), from the set $\Z \setminus 0$
(
!= 0). - nnz
- Non-negative integer numbers (m/o), from the set $\Z^*$
($\N _0$) (
>= 0). - npz
- Non-positive integer numbers (m), from the set $\Z^- \cup {0}$
(
<= 0). - nz
- Negative integer numbers (m/o), from the set $\Z^-$
(
< 0). - prime
- Prime numbers (m/o/w), from the set $\Bbb{P}$.
- pz
- Positive integer numbers (m/o), from the set $\Z^+$ ($\N _1$) (
> 0). - z
- Integer numbers (m/o/w), from the set $\Z$.
Structs§
- Integer8
- An 8-bit integer number, from the set $\Z$,
also known as
Z8. - Integer16
- A 16-bit integer number, from the set $\Z$,
also known as
Z16. - Integer32
- A 32-bit integer number, from the set $\Z$,
also known as
Z32. - Integer64
- A 64-bit integer number, from the set $\Z$,
also known as
Z64. - Integer128
- A 128-bit integer number, from the set $\Z$,
also known as
Z128. - Integer
Big big - A big integer number, from the set $\Z$,
also known as
ZBig. - Negative
Integer8 - An 8-bit negative integer number, from the set $\Z^-$,
also known as
Nz8. - Negative
Integer16 - A 16-bit negative integer number, from the set $\Z^-$,
also known as
Nz16. - Negative
Integer32 - A 32-bit negative integer number, from the set $\Z^-$,
also known as
Nz32. - Negative
Integer64 - A 64-bit negative integer number, from the set $\Z^-$,
also known as
Nz64. - Negative
Integer128 - A 128-bit negative integer number, from the set $\Z^-$,
also known as
Nz128. - NonNegative
Integer8 - An 8-bit non-negative integer number, from the set $\Z^*$ ($\N _0$),
also known as
Nnz8. - NonNegative
Integer16 - A 16-bit non-negative integer number, from the set $\Z^*$ ($\N _0$),
also known as
Nnz16. - NonNegative
Integer32 - A 32-bit non-negative integer number, from the set $\Z^*$ ($\N _0$),
also known as
Nnz32. - NonNegative
Integer64 - A 64-bit non-negative integer number, from the set $\Z^*$ ($\N _0$),
also known as
Nnz64. - NonNegative
Integer128 - A 128-bit non-negative integer number, from the set $\Z^*$ ($\N _0$),
also known as
Nnz128. - NonPositive
Integer8 - An 8-bit non-positive integer number, from the set $\Z^- \cup {0}$,
also known as
Npz8. - NonPositive
Integer16 - A 16-bit non-positive integer number, from the set $\Z^- \cup {0}$,
also known as
Npz16. - NonPositive
Integer32 - A 32-bit non-positive integer number, from the set $\Z^- \cup {0}$,
also known as
Npz32. - NonPositive
Integer64 - A 64-bit non-positive integer number, from the set $\Z^- \cup {0}$,
also known as
Npz64. - NonPositive
Integer128 - A 128-bit non-positive integer number, from the set $\Z^- \cup {0}$,
also known as
Npz128. - NonZero
Integer8 - A 8-bit non-zero integer number, from the set $\Z \setminus 0$,
also known as
N0z8. - NonZero
Integer16 - A 16-bit non-zero integer number, from the set $\Z \setminus 0$,
also known as
N0z16. - NonZero
Integer32 - A 32-bit non-zero integer number, from the set $\Z \setminus 0$,
also known as
N0z32. - NonZero
Integer64 - A 64-bit non-zero integer number, from the set $\Z \setminus 0$,
also known as
N0z64. - NonZero
Integer128 - A 128-bit non-zero integer number, from the set $\Z \setminus 0$,
also known as
N0z128. - Positive
Integer8 - An 8-bit positive integer number, from the set $\Z^+$ ($\N _1$),
also known as
Pz8. - Positive
Integer16 - A 16-bit positive integer number, from the set $\Z^+$ ($\N _1$),
also known as
Pz16. - Positive
Integer32 - A 32-bit positive integer number, from the set $\Z^+$ ($\N _1$),
also known as
Pz32. - Positive
Integer64 - A 64-bit positive integer number, from the set $\Z^+$ ($\N _1$),
also known as
Pz64. - Positive
Integer128 - A 128-bit positive integer number, from the set $\Z^+$ ($\N _1$),
also known as
Pz128. - Prime8
- An 8-bit prime number, from the set $\Bbb{P}$,
also known as
P8. - Prime16
- A 16-bit prime number, from the set $\Bbb{P}$,
also known as
P16. - Prime32
- A 32-bit prime number, from the set $\Bbb{P}$,
also known as
P32. - Prime64
- A 64-bit prime number, from the set $\Bbb{P}$,
also known as
P64. - Prime128
- A 128-bit prime number, from the set $\Bbb{P}$,
also known as
P128.
Enums§
- AllIntegers
- The family of all kinds of integers, also known as
AllZ. - Integers
- The family of integer numbers, also known as
Z. - Negative
Integers - The family of negative integers, also known as
Nz. - NonNegative
Integers - The family of non-negative integers, also known as
Nnz. - NonPositive
Integers - The family of non-positive integers, also known as
Npz. - NonZero
Integers - The family of non-zero integers, also known as
N0z. - Positive
Integers - The family of positive integers, also known as
Pz. - Primes
- The family of prime numbers, also known as
P.
Constants§
- LARGEST_
PRIME_ POW2_ DOUBLINGS - The largest primes that fit in the bits of consecutive doublings of powers of two.
- PRIMES_
BELL - The first 7 Bell primes (w) (A051131).
- PRIMES_
U8 - The list of the first 54 primes that fit in a
u8. - PRIMES_
U16 - The list of the 6,542 primes that fit in a
u16, minus the first 54. - TEN_
PRIMES_ LESS_ POW2 - The list of the 10 primes just less than each power of two between 8 and 400 bits.
Traits§
Functions§
- bit_len
big - Returns the minimum binary bits necessary to represent the given
integerin the givenbase. - bit_
len_ next_ power big - Returns the result of the
bit_lenfunction and the next power of 2. - is_
prime - Checks whether a
numberis prime, using optimized trial division. - is_
prime_ brute - Checks whether a
numberis prime, using basic trial division. - is_
prime_ sieve std - Checks whether a
numberis prime using an optimized sieve. - largest_
prime_ pow2_ doublings big - Returns a big integer containing the largest prime just less a power of two.
- nth_
prime - Finds the 0-indexed
nthprime number usingis_prime. - nth_
prime_ sieve std - Finds the 0-indexed
nthprime number usingis_prime_sievewith the providedupper_bound. - prime_
number_ theorem std - The prime number theorem (m/w) formula.
- prime_
pi - Counts the number of primes upto and including
n, usingis_prime. - prime_
pi_ sieve std - Counts the number of primes upto and including
nusingis_prime_sieve. - ten_
primes_ less_ pow2 big - Returns a big integer containing one of the ten largest primes just less than a power of two, between 8 and 400 bits.
Type Aliases§
- AllZ
- Abbreviation of
AllIntegersfamily. - Counting
- Alias of
PositiveIntegersfamily. - Counting8
- Alias of
PositiveInteger8. - Counting16
- Alias of
PositiveInteger16. - Counting32
- Alias of
PositiveInteger32. - Counting64
- Alias of
PositiveInteger64. - Counting128
- Alias of
PositiveInteger128. - N0z
- Abbreviation of
NonZeroIntegersfamily. - N0z8
- Abbreviation of
NonZeroInteger8. - N0z16
- Abbreviation of
NonZeroInteger16. - N0z32
- Abbreviation of
NonZeroInteger32. - N0z64
- Abbreviation of
NonZeroInteger64. - N0z128
- Abbreviation of
NonZeroInteger128. - Natural8
- Alias of
NonNegativeInteger8. - Natural16
- Alias of
NonNegativeInteger16. - Natural32
- Alias of
NonNegativeInteger32. - Natural64
- Alias of
NonNegativeInteger64. - Natural128
- Alias of
NonNegativeInteger128. - Naturals
- Alias of
NonNegativeIntegersfamily. - Nnz
- Abbreviation of
NonNegativeIntegersfamily. - Nnz8
- Abbreviation of
NonNegativeInteger8. - Nnz16
- Abbreviation of
NonNegativeInteger16. - Nnz32
- Abbreviation of
NonNegativeInteger32. - Nnz64
- Abbreviation of
NonNegativeInteger64. - Nnz128
- Abbreviation of
NonNegativeInteger128. - Npz
- Abbreviation of
NonPositiveIntegersfamily. - Npz8
- Abbreviation of
NonPositiveInteger8. - Npz16
- Abbreviation of
NonPositiveInteger16. - Npz32
- Abbreviation of
NonPositiveInteger32. - Npz64
- Abbreviation of
NonPositiveInteger64. - Npz128
- Abbreviation of
NonPositiveInteger128. - Nz
- Abbreviation of
NegativeIntegersfamily. - Nz8
- Abbreviation of
NegativeInteger8. - Nz16
- Abbreviation of
NegativeInteger16. - Nz32
- Abbreviation of
NegativeInteger32. - Nz64
- Abbreviation of
NegativeInteger64. - Nz128
- Abbreviation of
NegativeInteger128. - P
- Abbreviation of
Primesfamily. - P8
- Abbreviation of
Prime8. - P16
- Abbreviation of
Prime16. - P32
- Abbreviation of
Prime32. - P64
- Abbreviation of
Prime64. - P128
- Abbreviation of
Prime128. - Pz
- Abbreviation of
PositiveIntegersfamily. - Pz8
- Abbreviation of
PositiveInteger8. - Pz16
- Abbreviation of
PositiveInteger16. - Pz32
- Abbreviation of
PositiveInteger32. - Pz64
- Abbreviation of
PositiveInteger64. - Pz128
- Abbreviation of
PositiveInteger128. - Z
- Abbreviation of
Integersfamily. - Z8
- Abbreviation of
Integer8. - Z16
- Abbreviation of
Integer16. - Z32
- Abbreviation of
Integer32. - Z64
- Abbreviation of
Integer64. - Z128
- Abbreviation of
Integer128. - ZBig
big - Abbreviation of
IntegerBig.