[−][src]Trait maths_traits::algebra::group_like::multiplicative::PowZ
An auto-implemented trait for exponentiation by integers with associative and invertable types using inversion and repeated multiplication
This is intended as a simple and easy way to compute object powers in abstract algebraic
algorithms without resorting to explicitly applying multiplication repeatedly. For this reason, the
trait is automatically implemented for any relevant associative and invertable algebraic structure and
the supplied function is generic over the Integer
type.
assert_eq!(2.0f32.pow_z(3u8), 8.0); assert_eq!(2.0f32.pow_z(3u128), 8.0); assert_eq!(2.0f64.pow_z(3u8), 8.0); assert_eq!(2.0f64.pow_z(3u128), 8.0); assert_eq!(2.0f32.pow_z(-3i8), 0.125); assert_eq!(2.0f32.pow_z(-3i64), 0.125);
Note, however, that while exponentiation by integers is very simply defined using repeated multiplication and inversion, 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_squaring_inv algorithm
Specifically, for a given Natural type N
, the auto-impl will first attempt to use
Pow<N>
, if implemented, then if that fails, it will use the general
repeated_squaring_inv algorithm