Skip to content

Commit e29ff49

Browse files
committed
Added function versions of bitwise operations
Element wise operations now panic if the corresponding upstream operation returned an error code
1 parent 9b311bd commit e29ff49

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/arith/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ impl<'f> Not for &'f Array {
9999
fn not(self) -> Array {
100100
unsafe {
101101
let mut temp: i64 = 0;
102-
af_not(&mut temp as MutAfArray, self.get() as AfArray);
103-
Array::from(temp)
102+
match af_not(&mut temp as MutAfArray, self.get() as AfArray) {
103+
0 => Array::from(temp),
104+
_ => panic!("Negation of Array failed, please check input"),
105+
}
104106
}
105107
}
106108
}
@@ -184,6 +186,12 @@ binary_func!(add, af_add);
184186
binary_func!(sub, af_sub);
185187
binary_func!(mul, af_mul);
186188
binary_func!(div, af_div);
189+
binary_func!(rem, af_rem);
190+
binary_func!(bitand, af_bitand);
191+
binary_func!(bitor, af_bitor);
192+
binary_func!(bitxor, af_bitxor);
193+
binary_func!(shiftl, af_bitshiftl);
194+
binary_func!(shiftr, af_bitshiftr);
187195
binary_func!(lt, af_lt);
188196
binary_func!(gt, af_gt);
189197
binary_func!(le, af_le);
@@ -213,7 +221,7 @@ macro_rules! arith_scalar_func {
213221
match $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
214222
cnst_arr.get() as AfArray, 0) {
215223
0 => Array::from(temp),
216-
_ => panic!("Arithmetic operator on Array failed with error code"),
224+
_ => panic!("Arithmetic operator on Array failed"),
217225
}
218226
}
219227
}
@@ -248,10 +256,12 @@ macro_rules! arith_func {
248256
fn $fn_name(self, rhs:&'f Array) -> Array {
249257
unsafe {
250258
let mut temp: i64 = 0;
251-
$ffi_fn(&mut temp as MutAfArray,
252-
self.get() as AfArray, rhs.get() as AfArray,
253-
0);
254-
Array::from(temp)
259+
match $ffi_fn(&mut temp as MutAfArray,
260+
self.get() as AfArray, rhs.get() as AfArray,
261+
0) {
262+
0 => Array::from(temp),
263+
_ => panic!("Failed to perform arithmetic operation"),
264+
}
255265
}
256266
}
257267
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub use algorithm::{accum, locate, diff1, diff2, sort, sort_index, sort_by_key};
1010
pub use algorithm::{set_unique, set_union, set_intersect};
1111
mod algorithm;
1212

13-
pub use arith::{add, sub, div, mul, lt, gt, le, ge, eq, neq, and, or, minof, maxof};
13+
pub use arith::{add, sub, div, mul, lt, gt, le, ge, eq, neq, and, or, minof, maxof, rem};
14+
pub use arith::{bitand, bitor, bitxor, shiftl, shiftr};
1415
pub use arith::{abs, sign, round, trunc, floor, ceil, modulo};
1516
pub use arith::{sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh};
1617
pub use arith::{atan2, cplx2, arg, cplx, real, imag, conjg, hypot};

0 commit comments

Comments
 (0)