Opis is an arithmetic library for integer numbers written in Rust.
In your Cargo.toml
:
```
[dependencies] opis = "2.2.0"
```
In your Rust file:
```
use opis::{Bit, Int, pow, modulo, mod_inv};
```
Add
let sum: Int = a + b;
AddAssign
let total: Int = a += b;
Sub
let sum: Int = a - b;
SubAssign
let reduced: Int = a -= b;
Mul
let product: Int = a * b;
Div
let quotient: Int = a / b;
Rem
let rem: Int = a % b;
Not
let not_a: Int = !a;
BitAnd
let a_and_b: Int = a & b;
BitOr
let a_or_b: Int = a | b;
BitXor
let a_xor_b: Int = a ^ b;
Eq
```
if a == b {
println!("equal!")
}
if a != b { println!("not equal!") } ```
Ord
```
if a > b {
println!("a is greater!")
}
if a < b { println!("a is less!") } ```
Exponentiation
```
use opis::pow;
let e: Int = pow(&a, &b); ```
Modulo
```
use opis::modulo;
let m: Int = modulo(&a, &b); ```
Modular multiplicative inverse
```
use opis::mod_inv;
let i: Int = mod_inv(&a, &b); ```
From Str
```
let binary_integer: Int = Int::from("b'1010101");
let decimal_integer: Int = Int::from("674755");
let hex_integer: Int = Int::from("0x00ABC012");
```
To Str
```
let binarystr: String = integer1.to(2);
let decimalstr: String = integer2.tO(10);
let hexstr: String = integer3.to(16); ```
From Bytes
```
let integer: Int = Int::from_bytes(&bytes);
```
To Bytes
```
let bytes: Vec
```
Pull requests, bug reports and any kind of suggestion are welcome.
2022-02-09