[#2] Cleaned up the base traits.
I have switched to using the `core::` calling convention instead of using the `std::` by means of `extern crate core as std`. This makes it so that the library is easier to reason. The `Number` trait has been broken up now into `Number` and `Natural`. This was done to make it so that the pure mathematical types were separate from the Rust implementation types. I went and added better comments, including examples. The macros were tightened up so that the implementations took up less space. The FromNumber and ToNumber stuff will need to be reimplemented yet. Some of it seemed redundant with From and TryFrom traits now. It will be something to come back to and implement at the end.
This commit is contained in:
32
src/natural.rs
Normal file
32
src/natural.rs
Normal file
@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Sealed with Magistamp.
|
||||
|
||||
use core::mem::size_of;
|
||||
use core::ops::{Add, Sub, Mul, Div, Rem};
|
||||
use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
|
||||
use core::str::FromStr;
|
||||
|
||||
use crate::number::Number;
|
||||
use crate::one::One;
|
||||
|
||||
|
||||
|
||||
/// A Natural number is a counting number from one to infinity.
|
||||
/// 1, 2, 3, 4, 5, 6, ...
|
||||
///
|
||||
/// Rust types that are in this category are:
|
||||
/// u8, u16, u32, u64, u128, usize
|
||||
pub trait Natural: Number + One +
|
||||
Add<Output=Self> + AddAssign +
|
||||
Sub<Output=Self> + SubAssign +
|
||||
Mul<Output=Self> + MulAssign +
|
||||
Div<Output=Self> + DivAssign +
|
||||
Rem<Output=Self> + RemAssign
|
||||
{
|
||||
/// Performs division and returns both the quotient and remainder.
|
||||
#[inline]
|
||||
fn div_rem(self, rhs: Self) -> (Self, Self)
|
||||
{
|
||||
(self / rhs, self % rhs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user