forked from Orchid/orchid
Preparation for sharing
- rustfmt - clippy - comments - README
This commit is contained in:
34
src/external/num/operators/remainder.rs
vendored
34
src/external/num/operators/remainder.rs
vendored
@@ -1,40 +1,36 @@
|
||||
|
||||
use super::super::Numeric;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use super::super::Numeric;
|
||||
use crate::representations::interpreted::ExprInst;
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
|
||||
/// Remainder function
|
||||
///
|
||||
/// Takes the modulus of two numbers.
|
||||
///
|
||||
/// Next state: [Remainder1]
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Remainder2;
|
||||
externfn_impl!(Remainder2, |_: &Self, x: ExprInst| Ok(Remainder1{x}));
|
||||
externfn_impl!(Remainder2, |_: &Self, x: ExprInst| Ok(Remainder1 { x }));
|
||||
|
||||
/// Partially applied Remainder function
|
||||
///
|
||||
/// Prev state: [Remainder2]; Next state: [Remainder0]
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Remainder1{ x: ExprInst }
|
||||
pub struct Remainder1 {
|
||||
x: ExprInst,
|
||||
}
|
||||
atomic_redirect!(Remainder1, x);
|
||||
atomic_impl!(Remainder1);
|
||||
externfn_impl!(Remainder1, |this: &Self, x: ExprInst| {
|
||||
let a: Numeric = this.x.clone().try_into()?;
|
||||
Ok(Remainder0{ a, x })
|
||||
Ok(Remainder0 { a, x })
|
||||
});
|
||||
|
||||
/// Fully applied Remainder function.
|
||||
///
|
||||
/// Prev state: [Remainder1]
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Remainder0 { a: Numeric, x: ExprInst }
|
||||
pub struct Remainder0 {
|
||||
a: Numeric,
|
||||
x: ExprInst,
|
||||
}
|
||||
atomic_redirect!(Remainder0, x);
|
||||
atomic_impl!(Remainder0, |Self{ a, x }: &Self, _| {
|
||||
atomic_impl!(Remainder0, |Self { a, x }: &Self, _| {
|
||||
let b: Numeric = x.clone().try_into()?;
|
||||
Ok((*a % b).into())
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user