mathlab

Crates.iomathlab
lib.rsmathlab
version1.2.0
sourcesrc
created_at2021-02-26 19:02:59.11636
updated_at2024-10-31 16:24:36.440819
descriptionA Powerful Math Library for Rust
homepagehttps://github.com/dr-montasir/mathlab
repositoryhttps://github.com/dr-montasir/mathlab
max_upload_size
id361031
size194,199
Dr. Montasir (dr-montasir)

documentation

README

githubcrates.iodocs.rslicense

MathLab logo

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

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_F64NINF_F32NINF_F64PHIPIQ_PITAU

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_degacscacsc_degacschacsch_degasecasec_degasechasech_degasinasin_degasinhasinh_degatanatan_degatanhatanh_degcbrtceilcotcot_degcothcoth_degcoscos_degcoshcosh_degcsccsc_degcschcsch_degcubedeg_to_raddiviexpf64_to_f32factfixfix64floorfroundgammai64_to_f64invis_inf_f32is_inf_f64is_nan_f32is_nan_f64is_ninf_f32is_ninf_f64lnln1plog2log10multnrtperimeterpowrad_to_degremroundsecsec_degsechsech_degsignsinsin_degsinhsinh_degsqrsqrtsubttantan_degtanhtanh_degtruncu64_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_vecacsc_deg_vecacsch_vecacsch_deg_vecasec_vecasec_deg_vecasech_vecasech_deg_vecasin_vecasin_deg_vecasinh_vecasinh_deg_vecatan_vecatan_deg_vecatanh_vecatanh_deg_veccbrt_vecceil_veccos_veccos_deg_veccosh_veccosh_deg_veccot_veccot_deg_veccoth_veccoth_deg_veccsc_veccsc_deg_veccsch_veccsch_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_vecrand_vecround_vecsec_vecsec_deg_vecsech_vecsech_deg_vecsign_vecsin_deg_vecsin_vecsinh_vecsinh_deg_vecsqr_vecsqrt_vecstring_to_u64_vectan_deg_vectan_vectanh_vectanh_deg_vectrunc_vecu64_to_f64_vec

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
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
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.

All Items[ 209 ]

crates.io

docs.rs

license

github

Commit count: 55

cargo fmt