#science

cauchy

Trait for real and complex numbers

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

#1593 in Algorithms

Download history 3371/week @ 2023-08-08 3032/week @ 2023-08-15 4034/week @ 2023-08-22 3168/week @ 2023-08-29 3085/week @ 2023-09-05 2951/week @ 2023-09-12 3099/week @ 2023-09-19 2913/week @ 2023-09-26 3362/week @ 2023-10-03 3676/week @ 2023-10-10 3009/week @ 2023-10-17 3314/week @ 2023-10-24 3447/week @ 2023-10-31 4032/week @ 2023-11-07 3174/week @ 2023-11-14 3066/week @ 2023-11-21

14,337 downloads per month
Used in 75 crates (7 directly)

MIT license

12KB
267 lines

Cauchy

Crate 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