fn compare(d1: &Decimal, d2: &Decimal) -> Ordering {
        // Even if the exponents are wildly different, disagreement in the coefficient's signs
        // still tells which value is bigger. This approach causes `-0` to be considered less than
        // `0`, which may seem a bit quirky. However, according to the Ion data model, `-0` is not
        // equal to `0`, so saying that it's less than zero is a reasonable conclusion.
        let sign_cmp = d1.coefficient.sign().cmp(&d2.coefficient.sign());
        if sign_cmp != Ordering::Equal {
            return sign_cmp;
        }

        // If the exponents match, we can compare the two coefficients directly.
        if d1.exponent == d2.exponent {
            // We've already confirmed that the coefficients' signs match, so we can skip to
            // comparing their magnitudes.
            return d1.coefficient.magnitude().cmp(&d2.coefficient.magnitude());
        }

        // If the exponents don't match, we need to scale one of the magnitudes to match the other
        // for comparison. For example, when comparing 16e3 and 1600e1, we can't compare the
        // magnitudes (16 and 1600) directly. Instead, we need to multiply 16 by 10^2 to compensate
        // for the difference in their exponents (3-1). Then we'll be comparing 1600 to 1600,
        // and can safely conclude that they are equal.

        // But first, a detour: Decimal zeros are a special case because we can't scale them via
        // multiplication.
        if *d1.coefficient.magnitude() == Magnitude::U64(0)
            && *d2.coefficient.magnitude() == Magnitude::U64(0)
        {
            // Ion only considers zeros with the same sign to be equal if their exponents are
            // equal. We already know the exponents are different, but we still need to decide
            // between Ordering::Greater and Ordering::Less. We can order the zeros by comparing
            // their exponents.
            return d1.exponent.cmp(&d2.exponent);
        }

        // Scale up the magnitude associated with a lesser exponent and compare it with the
        // other magnitude.
        if d1.exponent < d2.exponent {
            Self::compare_scaled_magnitudes(d1, d2)
        } else {
            Self::compare_scaled_magnitudes(d2, d1)
        }
    }
// Used in the implementation of Ord, which compares the sign of each decimal before
// comparing the combined value of their exponents/magnitudes.
Used in the implementation of Ord, which compares the sign of each decimal before
comparing the combined value of their exponents/magnitudes.
Used in the implementation of Ord which compares the sign of each decimal before comparing the combined value of their exponents / magnitudes .
fn compare(d1: &Decimal, d2: &Decimal) -> Ordering {
        // Even if the exponents are wildly different, disagreement in the coefficient's signs
        // still tells which value is bigger. This approach causes `-0` to be considered less than
        // `0`, which may seem a bit quirky. However, according to the Ion data model, `-0` is not
        // equal to `0`, so saying that it's less than zero is a reasonable conclusion.
        let sign_cmp = d1.coefficient.sign().cmp(&d2.coefficient.sign());
        if sign_cmp != Ordering::Equal {
            return sign_cmp;
        }
        // If the exponents match, we can compare the two coefficients directly.
        if d1.exponent == d2.exponent {
            // We've already confirmed that the coefficients' signs match, so we can skip to
            // comparing their magnitudes.
            return d1.coefficient.magnitude().cmp(&d2.coefficient.magnitude());
        }
        // If the exponents don't match, we need to scale one of the magnitudes to match the other
        // for comparison. For example, when comparing 16e3 and 1600e1, we can't compare the
        // magnitudes (16 and 1600) directly. Instead, we need to multiply 16 by 10^2 to compensate
        // for the difference in their exponents (3-1). Then we'll be comparing 1600 to 1600,
        // and can safely conclude that they are equal.
        // But first, a detour: Decimal zeros are a special case because we can't scale them via
        // multiplication.
        if *d1.coefficient.magnitude() == Magnitude::U64(0)
            && *d2.coefficient.magnitude() == Magnitude::U64(0)
        {
            // Ion only considers zeros with the same sign to be equal if their exponents are
            // equal. We already know the exponents are different, but we still need to decide
            // between Ordering::Greater and Ordering::Less. We can order the zeros by comparing
            // their exponents.
            return d1.exponent.cmp(&d2.exponent);
        }
        // Scale up the magnitude associated with a lesser exponent and compare it with the
        // other magnitude.
        if d1.exponent < d2.exponent {
            Self::compare_scaled_magnitudes(d1, d2)
        } else {
            Self::compare_scaled_magnitudes(d2, d1)
        }
    }
fn compare ( d1 : & Decimal , d2 : & Decimal ) -> Ordering { // Even if the exponents are wildly different, disagreement in the coefficient's signs // still tells which value is bigger. This approach causes `-0` to be considered less than // `0`, which may seem a bit quirky. However, according to the Ion data model, `-0` is not // equal to `0`, so saying that it's less than zero is a reasonable conclusion. let sign_cmp = d1 . coefficient . sign ( ) . cmp ( & d2 . coefficient . sign ( ) ) ; if sign_cmp != Ordering :: Equal { return sign_cmp ; } // If the exponents match, we can compare the two coefficients directly. if d1 . exponent == d2 . exponent { // We've already confirmed that the coefficients' signs match, so we can skip to // comparing their magnitudes. return d1 . coefficient . magnitude ( ) . cmp ( & d2 . coefficient . magnitude ( ) ) ; } // If the exponents don't match, we need to scale one of the magnitudes to match the other // for comparison. For example, when comparing 16e3 and 1600e1, we can't compare the // magnitudes (16 and 1600) directly. Instead, we need to multiply 16 by 10^2 to compensate // for the difference in their exponents (3-1). Then we'll be comparing 1600 to 1600, // and can safely conclude that they are equal. // But first, a detour: Decimal zeros are a special case because we can't scale them via // multiplication. if * d1 . coefficient . magnitude ( ) == Magnitude :: U64 ( 0 ) && * d2 . coefficient . magnitude ( ) == Magnitude :: U64 ( 0 ) { // Ion only considers zeros with the same sign to be equal if their exponents are // equal. We already know the exponents are different, but we still need to decide // between Ordering::Greater and Ordering::Less. We can order the zeros by comparing // their exponents. return d1 . exponent . cmp ( & d2 . exponent ) ; } // Scale up the magnitude associated with a lesser exponent and compare it with the // other magnitude. if d1 . exponent < d2 . exponent { Self :: compare_scaled_magnitudes ( d1 , d2 ) } else { Self :: compare_scaled_magnitudes ( d2 , d1 ) } }
Used in the implementation of Ord, which compares the sign of each decimal before
comparing the combined value of their exponents/magnitudes.
Used in the implementation of Ord which compares the sign of each decimal before comparing the combined value of their exponents / magnitudes .
d1
&Decimal
d2
&Decimal
d1
&Decimal
d2
&Decimal