本文简要介绍rust语言中 u32.borrowing_sub
的用法。
用法
pub fn borrowing_sub(self, rhs: u32, borrow: bool) -> (u32, bool)
计算 self - rhs - borrow
而不会溢出。
执行“ternary subtraction”,它接受一个额外的位来减去,并可能返回一个额外的溢出位。这允许将多个减法链接在一起以创建表示较大值的“big integers”。
例子
基本用法
#![feature(bigint_helper_methods)]
assert_eq!(5u32.borrowing_sub(2, false), (3, false));
assert_eq!(5u32.borrowing_sub(2, true), (2, false));
assert_eq!(0u32.borrowing_sub(1, false), (u32::MAX, true));
assert_eq!(0u32.borrowing_sub(1, true), (u32::MAX - 1, true));
相关用法
- Rust u32.saturating_sub用法及代码示例
- Rust u32.unstable_next_multiple_of用法及代码示例
- Rust u32.wrapping_pow用法及代码示例
- Rust u32.checked_neg用法及代码示例
- Rust u32.overflowing_add用法及代码示例
- Rust u32.overflowing_div用法及代码示例
- Rust u32.carrying_mul用法及代码示例
- Rust u32.to_le_bytes用法及代码示例
- Rust u32.wrapping_shr用法及代码示例
- Rust u32.pow用法及代码示例
- Rust u32.leading_ones用法及代码示例
- Rust u32.swap_bytes用法及代码示例
- Rust u32.count_ones用法及代码示例
- Rust u32.log用法及代码示例
- Rust u32.checked_log用法及代码示例
- Rust u32.checked_pow用法及代码示例
- Rust u32.checked_add_signed用法及代码示例
- Rust u32.from_ne_bytes用法及代码示例
- Rust u32.to_le用法及代码示例
- Rust u32.checked_next_multiple_of用法及代码示例
- Rust u32.unstable_div_ceil用法及代码示例
- Rust u32.checked_div用法及代码示例
- Rust u32.from_be用法及代码示例
- Rust u32.overflowing_rem_euclid用法及代码示例
- Rust u32.overflowing_neg用法及代码示例
注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 u32.borrowing_sub。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。