drt_sc/types/managed/basic/
big_int_cmp.rs1use core::cmp::Ordering;
2
3use crate::api::{BigIntApiImpl, ManagedTypeApi};
4
5use super::{big_num_cmp::cmp_i64, BigInt};
6
7impl<M: ManagedTypeApi> PartialEq for BigInt<M> {
8 #[inline]
9 fn eq(&self, other: &Self) -> bool {
10 M::managed_type_impl()
11 .bi_cmp(self.handle.clone(), other.handle.clone())
12 .is_eq()
13 }
14}
15
16impl<M: ManagedTypeApi> Eq for BigInt<M> {}
17
18impl<M: ManagedTypeApi> PartialOrd for BigInt<M> {
19 #[inline]
20 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
21 Some(self.cmp(other))
22 }
23}
24
25impl<M: ManagedTypeApi> Ord for BigInt<M> {
26 #[inline]
27 fn cmp(&self, other: &Self) -> Ordering {
28 M::managed_type_impl().bi_cmp(self.handle.clone(), other.handle.clone())
29 }
30}
31
32macro_rules! partial_eq_and_ord {
33 ($small_int_type:ident) => {
34 impl<M: ManagedTypeApi> PartialEq<$small_int_type> for BigInt<M> {
35 #[inline]
36 fn eq(&self, other: &$small_int_type) -> bool {
37 cmp_i64(self, *other as i64).is_eq()
38 }
39 }
40
41 impl<M: ManagedTypeApi> PartialOrd<$small_int_type> for BigInt<M> {
42 #[inline]
43 fn partial_cmp(&self, other: &$small_int_type) -> Option<Ordering> {
44 Some(cmp_i64(self, *other as i64))
45 }
46 }
47 };
48}
49
50partial_eq_and_ord! {i32}
51partial_eq_and_ord! {i64}
52partial_eq_and_ord! {u32}
53partial_eq_and_ord! {u64}