Skip to content

v3.4.2 devel to master #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 26, 2017
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement arithmetic ops/triats for Array and &Array combinations
Earlier to this commit, arithmetic ops/traits were implemented for
only &Array type.
  • Loading branch information
9prady9 committed Feb 15, 2017
commit 607c96a3f4e7245b61472b82a32c2b795dd05842
54 changes: 36 additions & 18 deletions src/arith/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,33 +403,51 @@ arith_scalar_spec!(i32);
arith_scalar_spec!(u8);

macro_rules! arith_func {
($op_name:ident, $fn_name:ident, $ffi_fn: ident) => (
($op_name:ident, $fn_name:ident) => (
impl $op_name<Array> for Array {
type Output = Array;

fn $fn_name(self, rhs: Array) -> Array {
unsafe {
let mut temp: i64 = 0;
let err_val = $ffi_fn(&mut temp as MutAfArray,
self.get() as AfArray, rhs.get() as AfArray, 0);
HANDLE_ERROR(AfError::from(err_val));
Array::from(temp)
}
add(&self, &rhs, false)
}
}

impl<'a> $op_name<&'a Array> for Array {
type Output = Array;

fn $fn_name(self, rhs: &'a Array) -> Array {
add(&self, rhs, false)
}
}

impl<'a> $op_name<Array> for &'a Array {
type Output = Array;

fn $fn_name(self, rhs: Array) -> Array {
add(self, &rhs, false)
}
}

impl<'a, 'b> $op_name<&'a Array> for &'b Array {
type Output = Array;

fn $fn_name(self, rhs: &'a Array) -> Array {
add(self, rhs, false)
}
}
)
}

arith_func!(Add, add, af_add);
arith_func!(Sub, sub, af_sub);
arith_func!(Mul, mul, af_mul);
arith_func!(Div, div, af_div);
arith_func!(Rem, rem, af_rem);
arith_func!(BitAnd, bitand, af_bitand);
arith_func!(BitOr, bitor, af_bitor);
arith_func!(BitXor, bitxor, af_bitxor);
arith_func!(Shl, shl, af_bitshiftl);
arith_func!(Shr, shr, af_bitshiftr);
arith_func!(Add , add );
arith_func!(Sub , sub );
arith_func!(Mul , mul );
arith_func!(Div , div );
arith_func!(Rem , rem );
arith_func!(BitAnd, bitand);
arith_func!(BitOr , bitor );
arith_func!(BitXor, bitxor);
arith_func!(Shl , shl );
arith_func!(Shr , shr );

#[cfg(op_assign)]
mod op_assign {
Expand Down