nanvm_lib/vm/bigint/
bitor.rs1use core::ops::BitOr;
2
3use crate::vm::{BigInt, IVm};
4
5impl<A: IVm> BitOr for BigInt<A> {
6 type Output = Self;
7 fn bitor(self, rhs: Self) -> Self::Output {
8 self.bitwise_op(rhs, |a, b| a | b, |a_neg, b_neg| a_neg || b_neg)
9 }
10}
11
12#[cfg(test)]
13mod tests {
14 use crate::vm::bigint::test_util::{int, neg};
15
16 #[test]
17 fn both_positive() {
18 assert_eq!(int(0b1100) | int(0b1010), int(0b1110));
19 }
20
21 #[test]
22 fn both_negative() {
23 assert_eq!(int(-2) | int(-3), int(-1));
25 }
26
27 #[test]
28 fn mixed_signs() {
29 assert_eq!(int(5) | int(-1), int(-1));
31 assert_eq!(int(-1) | int(5), int(-1));
32 }
33
34 #[test]
35 fn with_zero() {
36 assert_eq!(int(0) | int(0), int(0));
37 assert_eq!(int(12_345) | int(0), int(12_345));
38 assert_eq!(int(-12_345) | int(0), int(-12_345));
39 }
40
41 #[test]
42 fn different_word_lengths() {
43 let x = neg([0u64, 1u64]);
47 let y = int(-1);
48 let expected = int(-1);
49 assert_eq!(x | y, expected);
50 }
51}