52 releases (3 stable)
1.2.0 | Oct 31, 2024 |
---|---|
0.9.6 | Sep 29, 2024 |
0.4.2 | Jul 31, 2024 |
0.1.1 | Feb 26, 2021 |
#78 in WebAssembly
184 downloads per month
Used in 2 crates
175KB
772 lines
MathLab
A Powerful Math Library for Rust
Install
Run the following Cargo command in your project directory:
cargo add mathlab
or
Add the following line to your Cargo.toml
file with the specified version:
mathlab = "MAJOR.MINOR.PATCH"
Changelog
https://github.com/dr-montasir/mathlab/blob/master/CHANGELOG.md
Usage
// examples
use mathlab::math;
fn main() {
let abs = math::abs(-2.0);
let add = math::add(0.1, 0.2);
let add_f64 = math::add(0.1, 0.2) as f64;
println!("{}", abs); // 2
println!("{}", add); // 0.30000000000000004
println!("{}", add_f64); // 0.30000000000000004
println!("{}", math::add(0.1, 0.2) as f32); // 0.3
println!("{}", math::fix64(0.1 + 0.2)); // 0.3
println!("{}", math::fix(0.1 + 0.2, 15)); // 0.3
println!("{}", math::to_fixed(0.1 + 0.2, 15)); // "0.3"
println!(
"{:?}",
math::subt_vec_vec(
&[0.1, 0.2, 0.3], &[0.3, 0.2, 0.1]
)
); // [-0.19999999999999998, 0.0, 0.19999999999999998]
println!(
// with vectors, use "{:?}" or "{:#?}".
"{:?}",
math::fix64_vec(
// Use the reference (&) before vector.
&math::subt_vec_vec(&[0.1, 0.2, 0.3], &[0.3, 0.2, 0.1]
))
); // [-0.2, 0.0, 0.2]
println!(
"{:?}",
math::sin_vec(&[0.5235987756, 1.5707963268])
); // [0.5, 1.0]
// [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
println!("{:?}", math::range(0.0, 0.1, 11, "asc"));
// [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]
println!("{:?}", math::range(1.0, 0.1, 11, "desc"));
println!(
"{:#?}",
math::sin_deg_vec(&math::range(0.0, 1.0, 361, "asc"))
); // [0.0, ..., 0.5, ..., 1.0, ..., 0.5, ..., 0.0]
}
or
// examples
use mathlab::math::{
abs, add, fix64, fix64_vec, fix,
to_fixed, range, sin_vec,
sin_deg_vec, subt_vec_vec
};
fn main() {
let my_abs = abs(-2.0);
let my_add = add(0.1, 0.2);
let my_add_f64 = add(0.1, 0.2) as f64;
println!("{}", my_abs); // 2
println!("{}", my_add); // 0.30000000000000004
println!("{}", my_add_f64); // 0.30000000000000004
println!("{}", add(0.1, 0.2) as f32); // 0.3
println!("{}", fix64(0.1 + 0.2)); // 0.3
println!("{}", fix(0.1 + 0.2, 15)); // 0.3
println!("{}", to_fixed(0.1 + 0.2, 15)); // "0.3"
println!(
"{:?}",
subt_vec_vec(
&[0.1, 0.2, 0.3], &[0.3, 0.2, 0.1]
)
); // [-0.19999999999999998, 0.0, 0.19999999999999998]
println!(
// with vectors, use "{:?}" or "{:#?}".
"{:?}",
fix64_vec(
// Use the reference (&) before vector.
&subt_vec_vec(&[0.1, 0.2, 0.3], &[0.3, 0.2, 0.1]
))
); // [-0.2, 0.0, 0.2]
println!(
"{:?}",
sin_deg_vec(&[30.0, 90.0])
); // [0.5, 1.0]
// [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
println!("{:?}", range(0.0, 0.1, 11, "asc"));
// [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]
println!("{:?}", range(1.0, 0.1, 11, "desc"));
println!(
"{:#?}",
sin_deg_vec(&range(0.0, 1.0, 361, "asc"))
); // [0.0, ..., 0.5, ..., 1.0, ..., 0.5, ..., 0.0]
}
Web 2.0 Demo Project
Web 3.0 Demo Project
Canister | Smart Contract |
On the Internet Computer, smart contracts come in the form of canisters. These are computational units which bundle together code and state.
Documentation
https://docs.rs/mathlab
MathLab :
A Powerful Math Library for Rust
All Items [ 209 ]
Modules
1. constants [ 16 items ]
constant | constant | constant |
---|---|---|
E | H_PI | INF_F32 |
INF_F64 | LN2 | LN10 |
LOG2E | LOG10E | NAN_F32 |
NAN_F64 NINF_F32 NINF_F64 PHI PI Q_PI TAU
2. functions [ 193 items ]
-
args [ 6 items ]
function | function | function |
---|---|---|
hypot | monolist | rand |
range | string_to_u64 | to_fixed |
-
num [ 88 items ]
function | function | function |
---|---|---|
abs | add | acos |
acos_deg | acosh | acosh_deg |
acot | acot_deg | acoth |
acoth_deg acsc acsc_deg acsch acsch_deg asec asec_deg asech asech_deg asin asin_deg asinh asinh_deg atan atan_deg atanh atanh_deg cbrt ceil cot cot_deg coth coth_deg cos cos_deg cosh cosh_deg csc csc_deg csch csch_deg cube deg_to_rad divi exp f64_to_f32 fact fix fix64 floor fround gamma i64_to_f64 inv is_inf_f32 is_inf_f64 is_nan_f32 is_nan_f64 is_ninf_f32 is_ninf_f64 ln ln1p log2 log10 mult nrt perimeter pow rad_to_deg rem round sec sec_deg sech sech_deg sign sin sin_deg sinh sinh_deg sqr sqrt subt tan tan_deg tanh tanh_deg trunc u64_to_f64
-
vec [ 75 items ]
function | function | function |
---|---|---|
abs_vec | acos_vec | acos_deg_vec |
acosh_vec | acosh_deg_vec | acot_vec |
acot_deg_vec | acoth_vec | acoth_deg_vec |
acsc_vec acsc_deg_vec acsch_vec acsch_deg_vec asec_vec asec_deg_vec asech_vec asech_deg_vec asin_vec asin_deg_vec asinh_vec asinh_deg_vec atan_vec atan_deg_vec atanh_vec atanh_deg_vec cbrt_vec ceil_vec cos_vec cos_deg_vec cosh_vec cosh_deg_vec cot_vec cot_deg_vec coth_vec coth_deg_vec csc_vec csc_deg_vec csch_vec csch_deg_vec cube_vec deg_to_rad_vec exp_vec f64_to_f32_vec fact_vec fix64_vec floor_vec fround_vec gamma_vec i64_to_f64_vec inv_vec ln_vec ln1p_vec log2_vec log10_vec rad_to_deg_vec rand_vec round_vec sec_vec sec_deg_vec sech_vec sech_deg_vec sign_vec sin_deg_vec sin_vec sinh_vec sinh_deg_vec sqr_vec sqrt_vec string_to_u64_vec tan_deg_vec tan_vec tanh_vec tanh_deg_vec trunc_vec u64_to_f64_vec
-
num_vec [ 8 items ]
function | function | function |
---|---|---|
add_num_vec | divi_num_vec | mult_num_vec |
nrt_num_vec | perimeter_num_vec | pow_num_vec |
rem_num_vec | subt_num_vec |
-
vec_num [ 8 items ]
function | function | function |
---|---|---|
add_vec_num | divi_vec_num | mult_vec_num |
nrt_vec_num | perimeter_vec_num | pow_vec_num |
rem_vec_num | subt_vec_num |
-
vec_vec [ 8 items ]
function | function | function |
---|---|---|
add_vec_vec | divi_vec_vec | mult_vec_vec |
nrt_vec_vec | perimeter_vec_vec | pow_vec_vec |
rem_vec_vec | subt_vec_vec |
3. math [ 209 items ]
The math module contains all constants and functions.