Skip to content

Commit 2cfc89e

Browse files
committed
[base] change struct name Sign to Signum (as it includes zero).
Signum is the mathematical function defined on real numbers which takes the values -1,0,+1. This should help to distinguish this struct from logically different uses, such as negation of expressions in the parser.
1 parent e7dcbfc commit 2cfc89e

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

base/src/onescomplement.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ pub mod error;
66
pub(crate) mod signed;
77
pub(crate) mod unsigned;
88

9-
/// The sign of a number. Although in a one's-complement system all
10-
/// values have a sign, we treat zero specially in order to simplify
11-
/// working with native types and one's-complement types together.
12-
pub(crate) enum Sign {
9+
/// The sign of a number (mathematically, sgn(x)). Although in a
10+
/// one's-complement system all values have a sign, we treat zero
11+
/// specially in order to simplify working with native types and
12+
/// one's-complement types together.
13+
pub(crate) enum Signum {
1314
Negative = -1, // <= -1
1415
Zero = 0, // +0 or -0
1516
Positive = 1, // >= +1
@@ -19,5 +20,5 @@ pub(crate) enum Sign {
1920
/// [`signed`] module) and unsigned types (defined in the [`unsigned`]
2021
/// module).
2122
pub(crate) trait WordCommon {
22-
fn signum(&self) -> Sign;
23+
fn signum(&self) -> Signum;
2324
}

base/src/onescomplement/signed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher};
44

55
use super::error::ConversionFailed;
66
use super::unsigned::*;
7-
use super::{Sign, WordCommon};
7+
use super::{Signum, WordCommon};
88

99
#[cfg(test)]
1010
mod tests18;
@@ -318,13 +318,13 @@ macro_rules! signed_ones_complement_impl {
318318
}
319319

320320
impl WordCommon for $SelfT {
321-
fn signum(&self) -> Sign {
321+
fn signum(&self) -> Signum {
322322
if self.is_zero() {
323-
Sign::Zero
323+
Signum::Zero
324324
} else if self.is_negative() {
325-
Sign::Negative
325+
Signum::Negative
326326
} else {
327-
Sign::Positive
327+
Signum::Positive
328328
}
329329
}
330330
}

base/src/onescomplement/unsigned.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use serde::Serialize;
1414
use super::super::subword::{right_half, split_halfword, split_halves};
1515
use super::error::ConversionFailed;
1616
use super::signed::*;
17-
use super::{Sign, WordCommon};
17+
use super::{Signum, WordCommon};
1818

1919
#[cfg(test)]
2020
mod tests;
@@ -257,13 +257,13 @@ macro_rules! unsigned_ones_complement_impl {
257257
}
258258

259259
impl WordCommon for $SelfT {
260-
fn signum(&self) -> Sign {
260+
fn signum(&self) -> Signum {
261261
if self.is_zero() {
262-
Sign::Zero
262+
Signum::Zero
263263
} else if self.is_negative() {
264-
Sign::Negative
264+
Signum::Negative
265265
} else {
266-
Sign::Positive
266+
Signum::Positive
267267
}
268268
}
269269
}

base/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::hash::{Hash, Hasher};
99
use super::onescomplement::error::ConversionFailed;
1010
use super::onescomplement::signed::{Signed18Bit, Signed5Bit, Signed6Bit};
1111
use super::onescomplement::unsigned::{Unsigned18Bit, Unsigned36Bit, Unsigned6Bit};
12-
use super::onescomplement::{Sign, WordCommon};
12+
use super::onescomplement::{Signum, WordCommon};
1313

1414
/// The `IndexBy` trait implements address arithmetic (adding a signed
1515
/// or unsigned value to an address).
@@ -181,9 +181,9 @@ fn signed_idx_impl(base: Address, delta: Signed18Bit) -> Result<Address, Convers
181181
let (current, mark) = base.split();
182182
let abs_delta: Unsigned18Bit = Unsigned18Bit::try_from(i32::from(delta.abs()))?;
183183
let physical = match delta.signum() {
184-
Sign::Zero => current,
185-
Sign::Positive => current.wrapping_add(abs_delta),
186-
Sign::Negative => current.wrapping_sub(abs_delta),
184+
Signum::Zero => current,
185+
Signum::Positive => current.wrapping_add(abs_delta),
186+
Signum::Negative => current.wrapping_sub(abs_delta),
187187
} & !PLACEHOLDER_MARK_BIT;
188188
Ok(Address::join(physical, mark))
189189
}

0 commit comments

Comments
 (0)