1use core::fmt;
7use numra_core::NumraError;
8
9#[derive(Clone, Debug, PartialEq)]
11pub enum IntegrationError {
12 MaxSubdivisions {
14 subdivisions: usize,
15 error_estimate: f64,
16 },
17 RoundoffDetected,
19 InvalidValue { x: f64 },
21 InvalidInput(String),
23}
24
25impl fmt::Display for IntegrationError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 IntegrationError::MaxSubdivisions {
29 subdivisions,
30 error_estimate,
31 } => {
32 write!(
33 f,
34 "Maximum subdivisions ({}) reached, error estimate: {:.2e}",
35 subdivisions, error_estimate
36 )
37 }
38 IntegrationError::RoundoffDetected => {
39 write!(f, "Roundoff error detected during integration")
40 }
41 IntegrationError::InvalidValue { x } => {
42 write!(f, "Integrand returned invalid value at x = {}", x)
43 }
44 IntegrationError::InvalidInput(msg) => {
45 write!(f, "Invalid input: {}", msg)
46 }
47 }
48 }
49}
50
51impl From<IntegrationError> for NumraError {
52 fn from(e: IntegrationError) -> Self {
53 NumraError::Integrate(e.to_string())
54 }
55}