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

#1909 in Algorithms

Download history 5295/week @ 2024-10-30 4493/week @ 2024-11-06 4825/week @ 2024-11-13 4621/week @ 2024-11-20 4773/week @ 2024-11-27 5259/week @ 2024-12-04 6287/week @ 2024-12-11 3697/week @ 2024-12-18 2197/week @ 2024-12-25 3754/week @ 2025-01-01 5049/week @ 2025-01-08 4945/week @ 2025-01-15 4275/week @ 2025-01-22 7542/week @ 2025-01-29 7298/week @ 2025-02-05 6350/week @ 2025-02-12

26,098 downloads per month
Used in 110 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.6–1MB
~18K SLoC