numera/number/integer/mod.rs
1// numera::number::integer
2//
3//! Integer numbers, subsets of $\Z$.
4//!
5//! An *integer* ([m][0m]/[w][0w]) is a number that can be written
6//! without a fractional component.
7//!
8//! [0m]: https://mathworld.wolfram.com/Integer.html
9//! [0w]: https://en.wikipedia.org/wiki/Integer
10//!
11//!
12//! # Integer subsets
13//!
14//! Different integer implementations are classified mathematically by:
15//! - Whether they only have positive sign (`PositiveInteger`, `NonNegativeInteger`),
16//! only negative sign (`NegativeInteger`, `NonPositiveInteger`),
17//! or both (`Integer`, `NonZeroInteger`).
18//! - Whether they support 0 (`Integer`, `NonNegativeInteger`, `NonPositiveInteger`)
19//! or not (`NonZeroInteger`, `PositiveInteger`, `NegativeInteger`).
20//!
21//! This makes for 6 different kinds of integers.
22//!
23//! They all implement the [`Integer`] trait, and are all variants of the
24//! [`Integers`] family enum, which includes also the special `Prime` kind.
25//!
26//! They are also classified computationally, by 6 choices on their bit-size
27//! representation: (`8`, `16`, `32`, `64`, `128` or `Big`). Combined makes for
28//! 36 choices of integers. (Except `Big` is only implemented for `Integer`
29//! for now).
30//!
31//! Note that numbers that can represent both positive an negative integers can
32//! represent half the max positive or negative value at the same bit-size than
33//! their only negative or positive counterparts. E.g.:
34//!
35// TODO
36//! ```ignore
37//! # use numera::all::*;
38//! assert_eq![[-128, 127], [Integer8::MIN, Integer8::MAX]];
39//! assert_eq![[-255, 255], [NonPositiveInteger8::MIN.into(), NonNegativeInteger8::MAX.into()]];
40//! ```
41//!
42//! # Operations
43//!
44//! Not all types have the same support for arithmetic operations, specially if
45//! we want the operation to return an integer of the same type.
46//!
47//! We say that a group is closed over an operation when that operation will
48//! always return a number of the same type. the following table summarizes
49//! the closed operations for each kind of integer:
50//!
51//! ||[`Integer`][z]|[`NonZero`][n0z]|[`NonNegative`][nnz]|[`Positive`][pz]|[`Nonpositive`][npz]|[`Negative`][nz]|[`Prime`][prime]|
52//! |:-:|:------:|:----------:|:----------:|:--------:|:----------:|:--------:|:----------:|
53//! |sign| + - | + - | + | + | - | - | + |
54//! |zero| 0 | | 0 | | 0 | | |
55//! ||
56//! | add| yes | | yes | yes | yes | yes | |
57//! | sub| yes | | | | | | |
58//! | mul| yes | yes | yes | yes | | | |
59//! | div| yes | yes | yes | yes | | | |
60//! | rem| yes | | yes | | yes | | |
61//! | neg| yes | yes | | | | | |
62//!
63//
64
65pub(crate) mod macros;
66
67mod family;
68mod fns;
69mod r#trait;
70
71pub mod n0z;
72pub mod nnz;
73pub mod npz;
74pub mod nz;
75pub mod pz;
76pub mod z;
77
78pub mod prime;
79
80pub use all::*;
81pub(crate) mod all {
82 #[doc(inline)]
83 pub use super::{
84 family::*, n0z::*, nnz::*, npz::*, nz::*, prime::all::*, pz::*, r#trait::Integer, z::*,
85 };
86
87 #[doc(inline)]
88 #[cfg(feature = "dashu-int")]
89 pub use super::{
90 fns::{bit_len, bit_len_next_power},
91 z::IntegerBig,
92 };
93}