base/onescomplement.rs
1//! This module implements one's complement fixed-width signed types
2//! for use in emulating the TX-2, plus related unsigned types of the
3//! same width.
4
5#[cfg(test)]
6use test_strategy::Arbitrary;
7
8pub mod error;
9pub(crate) mod signed;
10pub(crate) mod unsigned;
11
12/// The sign of a number (mathematically, sgn(x)). Although in a
13/// one's-complement system all values have a sign, we treat zero
14/// specially in order to simplify working with native types and
15/// one's-complement types together.
16#[cfg_attr(test, derive(Arbitrary))]
17#[derive(Debug)]
18pub(crate) enum Signum {
19 Negative = -1, // <= -1
20 Zero = 0, // +0 or -0
21 Positive = 1, // >= +1
22}
23
24/// Trait common to both signed one's-complement types (defined in the
25/// [`signed`] module) and unsigned types (defined in the [`unsigned`]
26/// module).
27pub(crate) trait WordCommon {
28 fn signum(&self) -> Signum;
29}