Skip to main content

numra_special/
error.rs

1//! Error types for special functions.
2//!
3//! Author: Moussa Leblouba
4//! Date: 9 February 2026
5//! Modified: 2 May 2026
6
7use core::fmt;
8
9/// Errors from special function evaluation.
10#[derive(Clone, Debug, PartialEq)]
11pub enum SpecialError {
12    /// Argument is outside the domain of the function.
13    Domain(String),
14    /// Series did not converge within the allowed iterations.
15    Convergence {
16        function: &'static str,
17        iterations: usize,
18    },
19}
20
21impl fmt::Display for SpecialError {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            Self::Domain(msg) => write!(f, "domain error: {msg}"),
25            Self::Convergence {
26                function,
27                iterations,
28            } => {
29                write!(
30                    f,
31                    "{function} did not converge after {iterations} iterations"
32                )
33            }
34        }
35    }
36}
37
38impl From<SpecialError> for numra_core::NumraError {
39    fn from(e: SpecialError) -> Self {
40        numra_core::NumraError::Special(e.to_string())
41    }
42}