您当前的位置: 首页 >  rust

mutourend

暂无认证

  • 3浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Rust u32 u64 的 wrapping_mul 包裹模乘运算

mutourend 发布时间:2019-07-12 17:05:49 ,浏览量:3

u64: 64-bit unsigned integer type

pub const fn wrapping_mul(self, rhs: u64) -> u64 Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

Examples: Please note that this example is shared between integer types. Which explains why u8 is used here.

assert_eq!(10u8.wrapping_mul(12), 120); // 10*12 mod 2^8 = 120
assert_eq!(25u8.wrapping_mul(12), 44); // 25*12 mod 2^8 = 300 mod 256 = 44
u32: 32-bit unsigned integer type

pub const fn wrapping_mul(self, rhs: u32) -> u32 Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

Examples: Please note that this example is shared between integer types. Which explains why u8 is used here.

assert_eq!(10u8.wrapping_mul(12), 120); // 10*12 mod 2^8 = 120
assert_eq!(25u8.wrapping_mul(12), 44); // 25*12 mod 2^8 = 300 mod 256 = 44

参考资料: [1] https://doc.rust-lang.org/std/primitive.u32.html#method.wrapping_mul [2] https://doc.rust-lang.org/std/primitive.u64.html#method.wrapping_mul

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.0766s