diff --git a/Cargo.toml b/Cargo.toml index b7c79f7..5d52bbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,10 @@ license = "MIT" [dependencies] num-traits = "0.2" serde = "1" -rand = "0.5" +rand = "0.7" [dependencies.num-complex] -version = "0.2.1" +git = "http://github.com/rust-num/num-complex" +rev = "7fb4f1c0f0f0d293c18df8d5b2b03362605b3862" +version = "0.3.0-pre" features = ["serde", "rand"] diff --git a/src/lib.rs b/src/lib.rs index fe01c32..9c16989 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,41 @@ -//! Scalar trait, which generalizes complex and real number. +//! Scalar trait for generic algorithm //! //! Examples //! -------- //! +//! Basic arithmetics with real/complex +//! //! ``` -//! # use cauchy::Scalar; +//! use cauchy::Scalar; +//! //! fn add_int(a: A) -> A { //! a + A::from(1).unwrap() // A::from is inhereted from num_traits::NumCast //! } +//! //! fn add_float(a: A) -> A { //! a + A::from(1.0).unwrap() //! } +//! //! fn add_real(a: A) -> A::Real { //! a.re() + A::real(1.0) //! } +//! //! fn add_complex(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() { +//! let mut rng = StdRng::from_entropy(); +//! let a = A::rand(&mut rng); +//! } +//! ``` use num_complex::Complex; use num_traits::{Float, FromPrimitive, NumAssign, NumCast, NumOps, ToPrimitive, Zero}; @@ -106,6 +124,8 @@ pub trait Scalar: fn acosh(&self) -> Self; fn atanh(&self) -> Self; + /// Generate an random number from + /// [rand::distributions::Standard](https://docs.rs/rand/0.7.2/rand/distributions/struct.Standard.html) fn rand(rng: &mut impl Rng) -> Self; }