#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum IntegrationStatus {
Success = 0,
MaxIterationsReached = 1,
RoundingErrorDetected = 2,
SingularityDetected = 3,
DivergenceDetected = 4,
PrecisionNotReached = 5,
DomainError = 6,
BadTolerance = 7,
OtherError = 8,
}
impl IntegrationStatus {
fn from_raw(v: i32) -> Self {
match v {
0 => Self::Success,
1 => Self::MaxIterationsReached,
2 => Self::RoundingErrorDetected,
3 => Self::SingularityDetected,
4 => Self::DivergenceDetected,
5 => Self::PrecisionNotReached,
6 => Self::DomainError,
7 => Self::BadTolerance,
_ => Self::OtherError,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct IntegrationResult {
pub status: IntegrationStatus,
pub value: f64,
pub abs_error: f64,
}
impl IntegrationResult {
pub(crate) fn from_raw(r: crate::ffi::OmeIntegrationResult) -> Self {
Self {
status: IntegrationStatus::from_raw(r.status),
value: r.result,
abs_error: r.abs_error,
}
}
}
macro_rules! mellin_moment_method {
($prefix:ident) => {
paste::paste! {
pub fn mellin_moment(
n: i32,
as_: f64,
lm: f64,
nf: f64,
eps_abs: f64,
eps_rel: f64,
) -> crate::mellin::IntegrationResult {
crate::mellin::IntegrationResult::from_raw(unsafe {
crate::ffi::[<ome_mellin_moment_ $prefix>](n, as_, lm, nf, eps_abs, eps_rel)
})
}
}
};
}
macro_rules! mellin_convolution_method {
($prefix:ident) => {
paste::paste! {
pub fn mellin_convolution(
x: f64,
as_: f64,
lm: f64,
nf: f64,
testfunc: unsafe extern "C" fn(f64) -> f64,
eps_abs: f64,
eps_rel: f64,
) -> crate::mellin::IntegrationResult {
crate::mellin::IntegrationResult::from_raw(unsafe {
crate::ffi::[<ome_mellin_convolution_ $prefix>](x, as_, lm, nf, testfunc, eps_abs, eps_rel)
})
}
}
};
}