Skip to main content

DigitSum

Trait DigitSum 

Source
pub trait DigitSum: Sized {
    // Required method
    fn digit_pow_sum(self, base: Self, exp: u32) -> Self;

    // Provided method
    fn digit_sum(self, base: Self) -> Self { ... }
}
Expand description

桁和。

§Examples

use nekolib::math::DigitSum;

assert_eq!(2_u32.pow(15).digit_sum(10), 3 + 2 + 7 + 6 + 8);
assert_eq!(123_u32.digit_pow_sum(10, 2), 1*1 + 2*2 + 3*3);
assert_eq!(0xACE_u32.digit_sum(16), 0xA + 0xC + 0xE);

assert_eq!(12345_u32.digit_pow_sum(10, 0), 5);  // the number of digits
assert_eq!(0_u32.digit_pow_sum(10, 0), 1);

Required Methods§

Source

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Provided Methods§

Source

fn digit_sum(self, base: Self) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl DigitSum for u8

Source§

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Source§

impl DigitSum for u16

Source§

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Source§

impl DigitSum for u32

Source§

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Source§

impl DigitSum for u64

Source§

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Source§

impl DigitSum for u128

Source§

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Source§

impl DigitSum for usize

Source§

fn digit_pow_sum(self, base: Self, exp: u32) -> Self

Implementors§