mathlab 0.6.5

A Powerful Math Library for Rust
Documentation

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

github

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]
}

Demo Project

Documentation

https://docs.rs/mathlab

MathLab :

A Powerful Math Library for Rust

All Items[ 148 ]

Modules

1. constants[ 16 items ]

constant constant constant
E H_PI INF_F32
INF_F64 LN2 LN10
LOG2E LOG10E NAN_F32

NAN_F64NINF_F32NINF_F64PHIPIQ_PITAU

2. functions[ 132 items ]

  • args[ 3 items ]

function function function
monolist range to_fixed
  • num[ 63 items ]

function function function
abs add acot
acot_deg acos acos_deg
acsc acsc_deg asec

asec_degasinasin_degatanatan_degcbrtceilcotcot_degcoscos_degcsccsc_degcubedeg_to_raddiviexpf64_to_f32factfixfix64floorfroundgammai64_to_f64invis_inf_f32is_inf_f64is_nan_f32is_nan_f64is_ninf_f32is_ninf_f64lnln1plog2log10multnrtpowrad_to_degremroundsecsec_degsignsinsin_degsqrsqrtsubttantan_degtruncu64_to_f64

  • vec[ 45 items ]

function function function
abs_vec acos_vec acos_deg_vec
acsc_vec acsc_deg_vec asin_vec
asin_deg_vec atan_vec atan_deg_vec

cbrt_vecceil_veccos_veccos_deg_veccot_veccot_deg_veccsc_veccsc_deg_veccube_vecdeg_to_rad_vecexp_vecf64_to_f32_vecfact_vecfix64_vecfloor_vecfround_vecgamma_veci64_to_f64_vecinv_vecln_vecln1p_veclog2_veclog10_vecrad_to_deg_vecround_vecsec_vecsec_deg_vecsign_vecsin_deg_vecsin_vecsqr_vecsqrt_vectan_deg_vectan_vectrunc_vecu64_to_f64_vec

function function function
add_num_vec divi_num_vec mult_num_vec
nrt_num_vec pow_num_vec rem_num_vec
subt_num_vec
function function function
add_vec_num divi_vec_num mult_vec_num
nrt_vec_num pow_vec_num rem_vec_num
subt_vec_num
function function function
add_vec_vec divi_vec_vec mult_vec_vec
nrt_vec_vec pow_vec_vec rem_vec_vec
subt_vec_vec

3. math[ 148 items ]

The math module contains all constants and functions.

All Items[ 148 ]

crates.io

docs.rs

license

github