50 releases (1 stable)

1.0.0 Oct 1, 2024
0.9.6 Sep 29, 2024
0.8.2 Sep 12, 2024
0.4.2 Jul 31, 2024
0.1.1 Feb 26, 2021

#51 in WebAssembly

Download history 880/week @ 2024-07-08 510/week @ 2024-07-15 822/week @ 2024-07-22 761/week @ 2024-07-29 264/week @ 2024-08-05 499/week @ 2024-08-12 830/week @ 2024-08-19 328/week @ 2024-08-26 9/week @ 2024-09-02 568/week @ 2024-09-09 495/week @ 2024-09-16 494/week @ 2024-09-23 413/week @ 2024-09-30

1,970 downloads per month
Used in solar

Apache-2.0

165KB
701 lines

githubcrates.iodocs.rslicense

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

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[ 205 ]

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[ 189 items ]

  • args[ 4 items ]

function function function
hypot monolist range
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[ 73 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_vecround_vecsec_vecsec_deg_vecsech_vecsech_deg_vecsign_vecsin_deg_vecsin_vecsinh_vecsinh_deg_vecsqr_vecsqrt_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[ 205 items ]

The math module contains all constants and functions.

All Items[ 205 ]

crates.io

docs.rs

license

github

No runtime deps