vildrose_core/word/
logic.rs1use super::Word;
2use crate::trit::Trit;
3
4impl<const N: usize> Word<N> {
5 #[must_use]
7 pub fn tmin(self, rhs: Self) -> Self {
8 Self(core::array::from_fn(|index| {
9 self.0[index].tmin(rhs.0[index])
10 }))
11 }
12
13 #[must_use]
15 pub fn tmax(self, rhs: Self) -> Self {
16 Self(core::array::from_fn(|index| {
17 self.0[index].tmax(rhs.0[index])
18 }))
19 }
20
21 #[must_use]
25 pub fn tnot(self) -> Self {
26 Self(self.0.map(Trit::negate))
27 }
28
29 #[must_use]
31 pub fn tclip(self) -> Self {
32 Self(self.0.map(Trit::clip))
33 }
34
35 #[must_use]
37 pub fn signum(self) -> Self {
38 Self(core::array::from_fn(|index| {
39 if index == 0 { self.sign() } else { Trit::Z }
40 }))
41 }
42
43 #[must_use]
45 pub fn tconsensus(self, rhs: Self) -> Self {
46 Self(core::array::from_fn(|index| {
47 self.0[index].consensus(rhs.0[index])
48 }))
49 }
50
51 #[must_use]
55 pub fn tshl(self, count: usize) -> Self {
56 Self(core::array::from_fn(|index| {
57 index
58 .checked_sub(count)
59 .and_then(|source| self.0.get(source).copied())
60 .unwrap_or(Trit::Z)
61 }))
62 }
63
64 #[must_use]
69 pub fn tshr(self, count: usize) -> Self {
70 let sign = self.sign();
71
72 Self(core::array::from_fn(|index| {
73 self.0
74 .get(index.saturating_add(count))
75 .copied()
76 .unwrap_or(sign)
77 }))
78 }
79
80 #[must_use]
85 pub fn tlshr(self, count: usize) -> Self {
86 Self(core::array::from_fn(|index| {
87 self.0
88 .get(index.saturating_add(count))
89 .copied()
90 .unwrap_or(Trit::Z)
91 }))
92 }
93}