Skip to content

Provide support for std number wrappers #79

Description

@DarkFenX

Two wrappers which help controlling behavior of overflow are Wrapping and Saturating.

This is general request, personally I need only small part of it. Currently, I have to reimplement LCM manually:

impl Count {
    pub(crate) fn lcm_saturating(self, other: Self) -> Self {
        if self == Self::ZERO || other == Self::ZERO {
            return Self::ZERO;
        }
        let gcd = num_integer::gcd(self.0, other.0);
        match (self.0 / gcd).checked_mul(other.0) {
            Some(lcm) => Self(lcm),
            None => Self::MAX,
        }
    }
}

When instead it could've been a thin wrapper around num_integer call:

impl Count {
    pub(crate) fn lcm_saturating(self, other: Self) -> Self {
        Count(num_integer::lcm(Saturating(self.0), Saturating(other.0)).0)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions