Skip to content

Commit

Permalink
!fixup adding check for divide by zero in init
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanam committed Jan 17, 2025
1 parent ebb14ec commit 9e246fa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/argmin/src/solver/itp/itp_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub enum ItpRootError {
/// max must be larger than min
#[error("ItpRoot error: max must be larger than min.")]
MinLargerThanMax,
/// max and min are equivalent
#[error("ItpRoot error: max is equivalent to min.")]
MaxEqualToMin,
}

/// # ITP method
Expand Down Expand Up @@ -114,6 +117,10 @@ impl<F: ArgminFloat> ItpRoot<F> {
/// kappa2 is defaulted to 2.0.
/// n0 is defaulted to 1.0.
pub fn from_defaults(min: F, max: F, tol: F) -> Result<Self, Error> {
if (max - min).is_zero() {
return Err(ItpRootError::MaxEqualToMin.into())
}

Self::new(
min,
max,
Expand Down

0 comments on commit 9e246fa

Please sign in to comment.