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

#1830 in Algorithms

Download history 3536/week @ 2024-01-03 3484/week @ 2024-01-10 3690/week @ 2024-01-17 2665/week @ 2024-01-24 2765/week @ 2024-01-31 3013/week @ 2024-02-07 4209/week @ 2024-02-14 3473/week @ 2024-02-21 4342/week @ 2024-02-28 4563/week @ 2024-03-06 3915/week @ 2024-03-13 5054/week @ 2024-03-20 4169/week @ 2024-03-27 4745/week @ 2024-04-03 4930/week @ 2024-04-10 4292/week @ 2024-04-17

19,101 downloads per month
Used in 82 crates (7 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.6–1MB
~18K SLoC