[][src]Trait maths_traits::algebra::group_like::additive::MulZ

pub trait MulZ: AddMonoid + Negatable {
    fn mul_z<N: IntegerSubset>(self, n: N) -> Self { ... }
}

An auto-implemented trait for multiplication by integers with associative and negatable types using negation and repeated addition

This is intended as a simple and easy way to compute object multiples in abstract algebraic algorithms without resorting to explicitly applying addition repeatedly. For this reason, the trait is automatically implemented for any relevant associative and negatable algebraic structure and the supplied function is generic over the Integer type.


 assert_eq!(2.5f32.mul_z(5u8), 12.5);
 assert_eq!(2.5f32.mul_z(5u128), 12.5);
 assert_eq!(2.5f64.mul_z(5u8), 12.5);
 assert_eq!(2.5f64.mul_z(5u128), 12.5);
 assert_eq!(2.5f32.mul_z(-5i8), -12.5);
 assert_eq!(2.5f32.mul_z(-5i64), -12.5);

Note, however, that while multiplication by integers is very simply defined using repeated addition and subtraction, in order to add flexibility in implementation and the possibility for proper optimization, the automatic implmentation of this trait will first try to use other traits as a base before defaulting to the general repeated_doubling_neg algorithm

Specifically, for a given Integer type Z, the auto-impl will first attempt to use Mul<Z>, if implemented. If that fails, it will then try to convert using From<Z> and multiplying if if it implemented and the struct is a Ring. Finally, in the general case, it will use the repeated_doubling_neg function.

Provided methods

fn mul_z<N: IntegerSubset>(self, n: N) -> Self

Loading content...

Implementors

impl<G: AddMonoid + Negatable> MulZ for G[src]

fn mul_z<N: IntegerSubset>(self, n: N) -> Self[src]

Loading content...