num-bigint icon indicating copy to clipboard operation
num-bigint copied to clipboard

Add powi method for `Sign` enum

Open feefladder opened this issue 1 year ago • 1 comments

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.

feefladder avatar Jan 23 '24 11:01 feefladder