pub struct LongDivision {
pub signed: bool,
}Expand description
A structure that defines the custom operation LongDivision that computes the quotient and
remainder of dividend / divisor, such that:
quotient * divisor + remainder == dividend
§Custom operation arguments
- Node containing the dividend as a two’s complement length-n bitstring.
- Node containing the divisor as a two’s complement length-n bitstring.
Only n which are powers of two are supported.
§Custom operation returns
Node containing the (quotient, remainder) tuple. Both quotient and remainder are bitstrings with lengths equal to dividend and divisor, respectively.
§Example
let t = array_type(vec![10, 25], INT32);
let c = simple_context(|g| {
let input_dividends = g.input(t.clone())?;
let input_divisors = g.input(t.clone())?;
let binary_dividends = input_dividends.a2b()?;
let binary_divisors = input_divisors.a2b()?;
let result = g.custom_op(
CustomOperation::new(LongDivision {
signed: true,
}),
vec![binary_dividends, binary_divisors],
)?;
let quotient = result.tuple_get(0)?.b2a(INT32)?;
let remainder = result.tuple_get(1)?.b2a(INT32)?;
g.create_tuple(vec![quotient, remainder])
}).unwrap();Fields§
§signed: boolTrait Implementations§
Source§impl CustomOperationBody for LongDivision
impl CustomOperationBody for LongDivision
Source§impl Debug for LongDivision
impl Debug for LongDivision
Source§impl<'de> Deserialize<'de> for LongDivision
impl<'de> Deserialize<'de> for LongDivision
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for LongDivision
impl Hash for LongDivision
Source§impl PartialEq for LongDivision
impl PartialEq for LongDivision
Source§impl Serialize for LongDivision
impl Serialize for LongDivision
impl Eq for LongDivision
impl StructuralPartialEq for LongDivision
Auto Trait Implementations§
impl Freeze for LongDivision
impl RefUnwindSafe for LongDivision
impl Send for LongDivision
impl Sync for LongDivision
impl Unpin for LongDivision
impl UnwindSafe for LongDivision
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.