Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Num Crate in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [3]:
:timing
:sccache 1
:dep num = "0.4.0"
In [4]:
use num;

num::integer::div_rem

In [5]:
let (div, rem) = num::integer::div_rem(8, 5);
println!("div: {}, rem: {}", div, rem);
div: 1, rem: 3

num::signum

In [6]:
num::signum(8)
Out[6]:
1
In [8]:
num::signum(-9)
Out[8]:
-1
In [9]:
num::signum(-0)
Out[9]:
0
In [10]:
num::signum(-0.0)
Out[10]:
-1.0

num::integer::binomial

The function num::integer::binomial(n, k) calculates the number of combinations of choosing k from n.

In [5]:
num::integer::binomial(4, 2)
Out[5]:
6
In [6]:
num::integer::binomial(10, 3)
Out[6]:
120
In [9]:
num::integer::binomial(3, 3)
Out[9]:
1
In [7]:
num::integer::binomial(1, 2)
Out[7]:
0
In [8]:
num::integer::binomial(2, 3)
Out[8]:
0
In [ ]:

Comments