Skip to content

Add powi method for Sign enum #289

Description

@feefladder

The multiplication method is provided, but raising a sign to an integer power is also a common use-case I think?

#[inline]
fn sign_powi<T: Integer>(sign: Sign, pow: T) -> Sign {
  if pow.is_odd() {sign} else {Sign::Plus}
}

or in an impl:

#[inline]
impl Sign {
  fn powi<T: Integer>(&self, pow: T) -> Sign {
    if pow.is_odd() {*self} else {Sign::Plus}
  }
}

I came here, because fraction crate uses Sign, which I use.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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