6 releases (3 breaking)

0.4.0 Mar 6, 2021
0.3.0 Jun 20, 2020
0.2.2 May 12, 2019
0.2.1 Apr 28, 2019
0.1.0 Dec 6, 2018

#1146 in Algorithms

Download history 5091/week @ 2024-07-23 4615/week @ 2024-07-30 4258/week @ 2024-08-06 4086/week @ 2024-08-13 3819/week @ 2024-08-20 5241/week @ 2024-08-27 4977/week @ 2024-09-03 3896/week @ 2024-09-10 4194/week @ 2024-09-17 5409/week @ 2024-09-24 4261/week @ 2024-10-01 4687/week @ 2024-10-08 5098/week @ 2024-10-15 3921/week @ 2024-10-22 5033/week @ 2024-10-29 4948/week @ 2024-11-05

20,004 downloads per month
Used in 103 crates (8 directly)

MIT license

12KB
267 lines

Cauchy

docs.rs Rust

Trait for real and complex numbers


lib.rs:

Scalar trait for generic algorithm

Examples

Basic arithmetics with real/complex

use cauchy::Scalar;

fn add_int<A: Scalar>(a: A) -> A {
    a + A::from(1).unwrap()  // A::from is inhereted from num_traits::NumCast
}

fn add_float<A: Scalar>(a: A) -> A {
    a + A::from(1.0).unwrap()
}

fn add_real<A: Scalar>(a: A) -> A::Real {
    a.re() + A::real(1.0)
}

fn add_complex<A: Scalar>(a: A) -> A::Complex {
    a.as_c() + A::complex(1.0, 1.0)  // upcast to complex if real
}

Random number generation

use cauchy::Scalar;
use rand::prelude::*;

fn random_algorithm<A: Scalar>() {
    let mut rng = StdRng::from_entropy();
    let a = A::rand(&mut rng);
}

Dependencies

~0.5–1MB
~18K SLoC