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

#2576 in Algorithms

Download history 7324/week @ 2025-12-23 7054/week @ 2025-12-30 14676/week @ 2026-01-06 13633/week @ 2026-01-13 13953/week @ 2026-01-20 12084/week @ 2026-01-27 15703/week @ 2026-02-03 13863/week @ 2026-02-10 17409/week @ 2026-02-17 15452/week @ 2026-02-24 18716/week @ 2026-03-03 17443/week @ 2026-03-10 14961/week @ 2026-03-17 19319/week @ 2026-03-24 16660/week @ 2026-03-31 22837/week @ 2026-04-07

76,395 downloads per month
Used in 161 crates (8 directly)

MIT license

12KB
267 lines

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);
}

Cauchy

docs.rs Rust

Trait for real and complex numbers

Dependencies

~0.6–1MB
~19K SLoC