本文簡要介紹rust語言中 u128.borrowing_sub
的用法。
用法
pub fn borrowing_sub(self, rhs: u128, borrow: bool) -> (u128, bool)
計算 self - rhs - borrow
而不會溢出。
執行“ternary subtraction”,它接受一個額外的位來減去,並可能返回一個額外的溢出位。這允許將多個減法鏈接在一起以創建表示較大值的“big integers”。
例子
基本用法
#![feature(bigint_helper_methods)]
assert_eq!(5u128.borrowing_sub(2, false), (3, false));
assert_eq!(5u128.borrowing_sub(2, true), (2, false));
assert_eq!(0u128.borrowing_sub(1, false), (u128::MAX, true));
assert_eq!(0u128.borrowing_sub(1, true), (u128::MAX - 1, true));
相關用法
- Rust u128.checked_pow用法及代碼示例
- Rust u128.to_be用法及代碼示例
- Rust u128.checked_shl用法及代碼示例
- Rust u128.checked_shr用法及代碼示例
- Rust u128.from_be_bytes用法及代碼示例
- Rust u128.wrapping_rem_euclid用法及代碼示例
- Rust u128.carrying_add用法及代碼示例
- Rust u128.from_be用法及代碼示例
- Rust u128.rotate_left用法及代碼示例
- Rust u128.count_ones用法及代碼示例
- Rust u128.checked_rem_euclid用法及代碼示例
- Rust u128.rotate_right用法及代碼示例
- Rust u128.saturating_pow用法及代碼示例
- Rust u128.is_power_of_two用法及代碼示例
- Rust u128.saturating_add用法及代碼示例
- Rust u128.overflowing_rem_euclid用法及代碼示例
- Rust u128.from_le用法及代碼示例
- Rust u128.saturating_div用法及代碼示例
- Rust u128.overflowing_rem用法及代碼示例
- Rust u128.wrapping_div用法及代碼示例
- Rust u128.leading_zeros用法及代碼示例
- Rust u128.overflowing_pow用法及代碼示例
- Rust u128.log2用法及代碼示例
- Rust u128.to_le_bytes用法及代碼示例
- Rust u128.checked_sub用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 u128.borrowing_sub。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。