Trait nekolib::math::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

Implementations on Foreign Types§

source§

impl DigitSum for u16

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 u64

source§

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

source§

impl DigitSum for u8

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 usize

source§

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

Implementors§