-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
114 changed files
with
72,032 additions
and
62,567 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod overflowing; | ||
pub use overflowing::{OverflowingAdd, OverflowingSub}; | ||
pub mod wrapping; |
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,49 @@ | ||
/// Performs addition that wraps around on overflow. | ||
pub trait WrappingAdd<T> { | ||
/// Wrapping (modular) addition. Computes `self + other`, wrapping around at the boundary of the | ||
/// type. | ||
fn wrapping_add(self: T, v: T) -> T; | ||
} | ||
|
||
/// Performs subtraction that wraps around on overflow. | ||
pub trait WrappingSub<T> { | ||
/// Wrapping (modular) subtraction. Computes `self - other`, wrapping around at the boundary of | ||
/// the type. | ||
fn wrapping_sub(self: T, v: T) -> T; | ||
} | ||
|
||
/// Performs multiplication that wraps around on overflow. | ||
pub trait WrappingMul<T> { | ||
/// Wrapping (modular) multiplication. Computes `self * other`, wrapping around at the boundary | ||
/// of the type. | ||
fn wrapping_mul(self: T, v: T) -> T; | ||
} | ||
|
||
pub(crate) mod overflow_based { | ||
pub(crate) impl TWrappingAdd< | ||
T, +core::num::traits::OverflowingAdd<T> | ||
> of core::num::traits::WrappingAdd<T> { | ||
fn wrapping_add(self: T, v: T) -> T { | ||
let (result, _) = self.overflowing_add(v); | ||
result | ||
} | ||
} | ||
|
||
pub(crate) impl TWrappingSub< | ||
T, +core::num::traits::OverflowingSub<T> | ||
> of core::num::traits::WrappingSub<T> { | ||
fn wrapping_sub(self: T, v: T) -> T { | ||
let (result, _) = self.overflowing_sub(v); | ||
result | ||
} | ||
} | ||
|
||
pub(crate) impl TWrappingMul< | ||
T, +core::num::traits::OverflowingMul<T> | ||
> of core::num::traits::WrappingMul<T> { | ||
fn wrapping_mul(self: T, v: T) -> T { | ||
let (result, _) = self.overflowing_mul(v); | ||
result | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.