Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Nov 11, 2023
1 parent 88e3adf commit 357bc19
Showing 1 changed file with 26 additions and 63 deletions.
89 changes: 26 additions & 63 deletions utils/fixed_decimal/src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,20 @@ impl FixedDecimal {
/// dec.trunc(0);
/// assert_eq!("1", dec.to_string());
/// ```
#[cfg(not(feature = "experimental"))]
pub fn trunc(&mut self, position: i16) {
#[cfg(feature = "experimental")]
{
self.trunc_to_increment(position, RoundingIncrement::MultiplesOf1);
}

#[cfg(not(feature = "experimental"))]
{
self.trunc_internal(position);
}
}

#[cfg(not(feature = "experimental"))]
fn trunc_internal(&mut self, position: i16) {
// 1. Set upper and lower magnitude
self.lower_magnitude = cmp::min(position, 0);
if position == i16::MIN {
Expand Down Expand Up @@ -1138,38 +1150,6 @@ impl FixedDecimal {
self.check_invariants();
}

/// Truncates the number on the right to a particular position, deleting
/// digits if necessary.
///
/// Also see [`FixedDecimal::pad_end()`].
///
/// # Examples
///
/// ```
/// use fixed_decimal::FixedDecimal;
/// # use std::str::FromStr;
///
/// let mut dec = FixedDecimal::from_str("-1.5").unwrap();
/// dec.trunc(0);
/// assert_eq!("-1", dec.to_string());
/// let mut dec = FixedDecimal::from_str("0.4").unwrap();
/// dec.trunc(0);
/// assert_eq!("0", dec.to_string());
/// let mut dec = FixedDecimal::from_str("0.5").unwrap();
/// dec.trunc(0);
/// assert_eq!("0", dec.to_string());
/// let mut dec = FixedDecimal::from_str("0.6").unwrap();
/// dec.trunc(0);
/// assert_eq!("0", dec.to_string());
/// let mut dec = FixedDecimal::from_str("1.5").unwrap();
/// dec.trunc(0);
/// assert_eq!("1", dec.to_string());
/// ```
#[cfg(feature = "experimental")]
pub fn trunc(&mut self, position: i16) {
self.trunc_to_increment(position, RoundingIncrement::MultiplesOf1)
}

/// Truncates the number on the right to a particular position and rounding
/// increment, deleting digits if necessary.
///
Expand Down Expand Up @@ -1449,8 +1429,20 @@ impl FixedDecimal {
/// dec.expand(0);
/// assert_eq!("2", dec.to_string());
/// ```
#[cfg(not(feature = "experimental"))]
pub fn expand(&mut self, position: i16) {
#[cfg(feature = "experimental")]
{
self.expand_to_increment(position, RoundingIncrement::MultiplesOf1);
}

#[cfg(not(feature = "experimental"))]
{
self.expand_internal(position);
}
}

#[cfg(not(feature = "experimental"))]
fn expand_internal(&mut self, position: i16) {
// 1. Set upper and lower magnitude
self.lower_magnitude = cmp::min(position, 0);
if position == i16::MIN {
Expand Down Expand Up @@ -1510,35 +1502,6 @@ impl FixedDecimal {
self.check_invariants();
}

/// Take the expand of the number at a particular position.
///
/// # Examples
///
/// ```
/// use fixed_decimal::FixedDecimal;
/// # use std::str::FromStr;
///
/// let mut dec = FixedDecimal::from_str("-1.5").unwrap();
/// dec.expand(0);
/// assert_eq!("-2", dec.to_string());
/// let mut dec = FixedDecimal::from_str("0.4").unwrap();
/// dec.expand(0);
/// assert_eq!("1", dec.to_string());
/// let mut dec = FixedDecimal::from_str("0.5").unwrap();
/// dec.expand(0);
/// assert_eq!("1", dec.to_string());
/// let mut dec = FixedDecimal::from_str("0.6").unwrap();
/// dec.expand(0);
/// assert_eq!("1", dec.to_string());
/// let mut dec = FixedDecimal::from_str("1.5").unwrap();
/// dec.expand(0);
/// assert_eq!("2", dec.to_string());
/// ```
#[cfg(feature = "experimental")]
pub fn expand(&mut self, position: i16) {
self.expand_to_increment(position, RoundingIncrement::MultiplesOf1)
}

/// Take the expand of the number at a particular position and rounding increment.
///
/// <div class="stab unstable">
Expand Down

0 comments on commit 357bc19

Please sign in to comment.