Skip to content

Commit

Permalink
Do not panic of tolerances are negative
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris00 committed Dec 23, 2023
1 parent 01da938 commit bf5831c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ pub trait Terminate<T> {
/// Indicate that the type `Self` uses relative and absolute
/// tolerances that can be updated from type `U`.
pub trait SetTolerances<U> {
/// Set the relative tolerance. Must panic if `rtol` is ≤ 0.
/// Set the relative tolerance. Set the default value if `rtol` is ≤ 0.
fn set_rtol(&mut self, rtol: U);
/// Set the absolute tolerance. Must panic if `atol` is < 0.
/// Set the absolute tolerance. Set the default value if `atol` is < 0.
fn set_atol(&mut self, atol: U);
}

Expand Down Expand Up @@ -152,14 +152,10 @@ macro_rules! impl_traits_tol_fXX {
// non-copy types `$t`.
impl SetTolerances<$t> for Tol<$t> {
fn set_rtol(&mut self, rtol: $t) {
if rtol <= 0. { panic!("root1d<{}>: rtol = {:e} ≤ 0",
stringify!($t), rtol) }
self.rtol = rtol;
self.rtol = if rtol <= 0. { $rtol } else { rtol }
}
fn set_atol(&mut self, atol: $t) {
if atol < 0. { panic!("root1d<{}>: atol = {:e} < 0",
stringify!($t), atol) }
self.atol = atol;
self.atol = if atol < 0. { $atol } else { atol }
}
}
}
Expand Down

0 comments on commit bf5831c

Please sign in to comment.