Skip to main content

IntegerExt

Trait IntegerExt 

Source
pub trait IntegerExt:
    Sized
    + Copy
    + Ord {
    // Provided methods
    fn div_rem(self, rhs: Self) -> (Self, Self)
       where Self: Div<Output = Self> + Rem<Output = Self> { ... }
    fn chmin(&mut self, rhs: Self) -> bool { ... }
    fn chmax(&mut self, rhs: Self) -> bool { ... }
}
Expand description

組み込み整数型に便利な整数演算を追加する拡張トレイトです。

すべての符号付き・符号なし組み込み整数型に実装されています。 div_rem は通常の整数除算に従い、除数 0 や符号付き最小値を -1 で割る場合は panic します。chmin と chmax は値を条件付きで更新し、その成否を bool で返します。

§Examples

use atcoder::math::integer::IntegerExt;

let mut value = 10_usize;
assert!(value.chmin(7));
assert!(!value.chmin(9));
assert_eq!(value, 7);

assert_eq!(10_usize.div_rem(3), (3, 1));

Provided Methods§

Source

fn div_rem(self, rhs: Self) -> (Self, Self)
where Self: Div<Output = Self> + Rem<Output = Self>,

商と余りを (self / rhs, self % rhs) の順に返します。

符号付き整数の商は 0 方向へ切り捨て、余りは self と同じ符号になります。 除数 rhs が 0 の場合など、通常の除算が panic する入力ではこのメソッドも panic します。

Source

fn chmin(&mut self, rhs: Self) -> bool

rhs が self より小さい場合に self を rhs で置き換えます。

値を置き換えた場合は true、そのままの場合は false を返します。

Source

fn chmax(&mut self, rhs: Self) -> bool

rhs が self より大きい場合に self を rhs で置き換えます。

値を置き換えた場合は true、そのままの場合は false を返します。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IntegerExt for i8

Source§

impl IntegerExt for i16

Source§

impl IntegerExt for i32

Source§

impl IntegerExt for i64

Source§

impl IntegerExt for i128

Source§

impl IntegerExt for isize

Source§

impl IntegerExt for u8

Source§

impl IntegerExt for u16

Source§

impl IntegerExt for u32

Source§

impl IntegerExt for u64

Source§

impl IntegerExt for u128

Source§

impl IntegerExt for usize

Implementors§

Source§

impl<const MAX: usize> IntegerExt for SaturatingUsize<MAX>