Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes
- Fix `Geometric::new` for small `p > 0` where `1 - p` rounds to 1 (#36)
- Fix panic in `FisherF::new` on almost zero parameters (#39)

## [0.5.2]

Expand Down
22 changes: 9 additions & 13 deletions src/fisher_f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

//! The Fisher F-distribution.

use crate::{ChiSquared, Distribution, Exp1, Open01, StandardNormal};
use crate::{ChiSquared, Distribution, Exp1, Open01, StandardNormal, chi_squared};
use core::fmt;
use num_traits::Float;
use rand::Rng;
Expand Down Expand Up @@ -57,9 +57,9 @@ where
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Error {
/// `m <= 0` or `nan`.
/// `0.5 * m <= 0.0` or `nan`.
MTooSmall,
/// `n <= 0` or `nan`.
/// `0.5 * n <= 0.0` or `nan`.
NTooSmall,
}

Expand All @@ -84,17 +84,13 @@ where
{
/// Create a new `FisherF` distribution, with the given parameter.
pub fn new(m: F, n: F) -> Result<FisherF<F>, Error> {
let zero = F::zero();
if !(m > zero) {
return Err(Error::MTooSmall);
}
if !(n > zero) {
return Err(Error::NTooSmall);
}

Ok(FisherF {
numer: ChiSquared::new(m).unwrap(),
denom: ChiSquared::new(n).unwrap(),
numer: ChiSquared::new(m).map_err(|x| match x {
chi_squared::Error::DoFTooSmall => Error::MTooSmall,
})?,
denom: ChiSquared::new(n).map_err(|x| match x {
chi_squared::Error::DoFTooSmall => Error::NTooSmall,
})?,
dof_ratio: n / m,
})
}
Expand Down