Implement Error and Display for all errors
This commit is contained in:
@@ -73,6 +73,10 @@ impl fmt::Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
// evaluate fact(numerator.0)*fact(numerator.1) / fact(denominator.0)*fact(denominator.1)
|
||||
fn fraction_of_products_of_factorials(numerator: (u64, u64), denominator: (u64, u64)) -> f64 {
|
||||
let min_top = u64::min(numerator.0, numerator.1);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{Distribution, Standard, StandardNormal};
|
||||
use num_traits::Float;
|
||||
use rand::Rng;
|
||||
use core::fmt;
|
||||
|
||||
/// Error type returned from `InverseGaussian::new`
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -11,6 +12,19 @@ pub enum Error {
|
||||
ShapeNegativeOrNull,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match self {
|
||||
Error::MeanNegativeOrNull => "mean <= 0 or is NaN in inverse Gaussian distribution",
|
||||
Error::ShapeNegativeOrNull => "shape <= 0 or is NaN in inverse Gaussian distribution",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// The [inverse Gaussian distribution](https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution)
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct InverseGaussian<F>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{Distribution, InverseGaussian, Standard, StandardNormal};
|
||||
use num_traits::Float;
|
||||
use rand::Rng;
|
||||
use core::fmt;
|
||||
|
||||
/// Error type returned from `NormalInverseGaussian::new`
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -11,6 +12,19 @@ pub enum Error {
|
||||
AbsoluteBetaNotLessThanAlpha,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match self {
|
||||
Error::AlphaNegativeOrNull => "alpha <= 0 or is NaN in normal inverse Gaussian distribution",
|
||||
Error::AbsoluteBetaNotLessThanAlpha => "|beta| >= alpha or is NaN in normal inverse Gaussian distribution",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// The [normal-inverse Gaussian distribution](https://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution)
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NormalInverseGaussian<F>
|
||||
|
||||
Reference in New Issue
Block a user