1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use core::ops::{BitXor, Not};

#[derive(Eq, PartialEq, Copy, Clone)]
pub(crate) struct Sign(bool);
impl Sign {
  pub(crate) const POSITIVE: Sign = Sign(false);
  pub(crate) const NEGATIVE: Sign = Sign(true);

  #[inline(always)]
  pub(crate) const fn is_negative(self) -> bool {
    self.0
  }

  #[inline(always)]
  pub(crate) const fn new(is_negative: bool) -> Sign {
    Sign(is_negative)
  }
}

impl Not for Sign {
  type Output = Self;

  #[inline(always)]
  fn not(self) -> Self::Output {
    Sign(!self.0)
  }
}

impl BitXor for Sign {
  type Output = Sign;

  #[inline(always)]
  fn bitxor(self, rhs: Self) -> Self::Output {
    Sign(self.0 != rhs.0)
  }
}