-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create module and traits for all integers and make math module generic
- Loading branch information
1 parent
26de88b
commit a0c80f6
Showing
7 changed files
with
82 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::cmp::{PartialEq, PartialOrd}; | ||
use std::ops::{Add, BitAnd, Div, Mul, Neg, Rem, Shr, Sub}; | ||
|
||
pub trait Integer<T>: | ||
Copy | ||
+ From<u8> | ||
+ PartialEq | ||
+ PartialOrd | ||
+ Add<Output = T> | ||
+ BitAnd<Output = T> | ||
+ Div<Output = T> | ||
+ Mul<Output = T> | ||
+ Rem<Output = T> | ||
+ Shr<Output = T> | ||
+ Sub<Output = T> | ||
{ | ||
const ZERO: T; | ||
const ONE: T; | ||
const TEN: T; | ||
} | ||
|
||
macro_rules! Integer { | ||
($($t:ty)*) => ($( | ||
impl Integer<$t> for $t { | ||
const ZERO: $t = 0; | ||
const ONE: $t = 1; | ||
const TEN: $t = 10; | ||
} | ||
|
||
)*) | ||
} | ||
|
||
Integer!(u8 u16 u32 u64 usize i16 i32 i64); | ||
|
||
pub trait Unsigned<T>: Integer<T> {} | ||
|
||
macro_rules! unsigned { | ||
($($t:ty)*) => ($( | ||
impl Unsigned<$t> for $t {} | ||
)*) | ||
} | ||
|
||
unsigned!(u8 u16 u32 u64 usize); | ||
|
||
pub trait Signed<T>: Integer<T> + Neg<Output = T> {} | ||
|
||
macro_rules! signed { | ||
($($t:ty)*) => ($( | ||
impl Signed<$t> for $t {} | ||
)*) | ||
} | ||
|
||
signed!(i16 i32 i64); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters