statrs/
lib.rs

1//! This crate aims to be a functional port of the Math.NET Numerics
2//! Distribution package and in doing so providing the Rust numerical computing
3//! community with a robust, well-tested statistical distribution package. This
4//! crate also ports over some of the special statistical functions from
5//! Math.NET in so far as they are used in the computation of distribution
6//! values. This crate depends on the `rand` crate to provide RNG.
7//!
8//! # Example
9//! The following example samples from a standard normal distribution
10//!
11//! ```
12//! # extern crate rand;
13//! # extern crate statrs;
14//! use rand::distributions::Distribution;
15//! use statrs::distribution::Normal;
16//!
17//! # fn main() {
18//! let mut r = rand::thread_rng();
19//! let n = Normal::new(0.0, 1.0).unwrap();
20//! for _ in 0..10 {
21//!     print!("{}", n.sample(&mut r));
22//! }
23//! # }
24//! ```
25
26#![crate_type = "lib"]
27#![crate_name = "statrs"]
28#![allow(clippy::excessive_precision)]
29#![allow(clippy::many_single_char_names)]
30#![allow(unused_imports)]
31#![forbid(unsafe_code)]
32#![cfg_attr(all(test, feature = "nightly"), feature(unboxed_closures))]
33#![cfg_attr(all(test, feature = "nightly"), feature(fn_traits))]
34
35#[macro_use]
36extern crate approx;
37
38#[macro_use]
39extern crate lazy_static;
40
41#[macro_export]
42macro_rules! assert_almost_eq {
43    ($a:expr, $b:expr, $prec:expr) => {
44        if !$crate::prec::almost_eq($a, $b, $prec) {
45            panic!(
46                "assertion failed: `abs(left - right) < {:e}`, (left: `{}`, right: `{}`)",
47                $prec, $a, $b
48            );
49        }
50    };
51}
52
53pub mod consts;
54#[macro_use]
55pub mod distribution;
56pub mod euclid;
57pub mod function;
58pub mod generate;
59pub mod prec;
60pub mod statistics;
61
62mod error;
63
64// function to silence clippy on the special case when comparing to zero.
65#[inline(always)]
66pub(crate) fn is_zero(x: f64) -> bool {
67    ulps_eq!(x, 0.0, max_ulps = 0)
68}
69
70// #[cfg(test)]
71mod testing;
72
73pub use crate::error::StatsError;
74
75/// Result type for the statrs library package that returns
76/// either a result type `T` or a `StatsError`
77pub type Result<T> = std::result::Result<T, StatsError>;