#![deny(rustdoc::broken_intra_doc_links)]
use crate::kernels::RawRealTrait;
use num::Integer;
use std::{backtrace::Backtrace, fmt::Display};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ErrorsValidationRawReal<RawReal: std::fmt::Debug + Display + Clone> {
#[error("Value is subnormal: {value}")]
IsSubnormal {
value: RawReal,
backtrace: Backtrace,
},
#[error("Value is NaN: {value}")]
IsNaN {
value: RawReal,
backtrace: Backtrace,
},
#[error("Value is positive infinity")]
IsPosInfinity {
backtrace: Backtrace,
},
#[error("Value is negative infinity")]
IsNegInfinity {
backtrace: Backtrace,
},
#[error(
"precision mismatch: input real has precision {actual_precision}, \
but the requested precision is {requested_precision}"
)]
PrecisionMismatch {
input_value: RawReal,
actual_precision: u32,
requested_precision: u32,
backtrace: Backtrace,
},
}
#[derive(Debug, Error)]
pub enum ErrorsValidationRawComplex<ErrorValidationReal: std::error::Error> {
#[error("Real part validation error: {source}")]
InvalidRealPart {
#[source]
#[backtrace]
source: Box<ErrorValidationReal>,
},
#[error("Imaginary part validation error: {source}")]
InvalidImaginaryPart {
#[source]
#[backtrace]
source: Box<ErrorValidationReal>,
},
#[error("Both real and imaginary parts are invalid: real={real_error}, imag={imag_error}")]
InvalidBothParts {
real_error: Box<ErrorValidationReal>,
imag_error: Box<ErrorValidationReal>,
},
}
#[derive(Debug, Error)]
pub enum ErrorsTryFromf64<RawReal: RawRealTrait> {
#[error(
"the input f64 value ({value_in:?}) cannot be exactly represented with the specific precision ({precision:?}). Try to increase the precision."
)]
NonRepresentableExactly {
value_in: f64,
value_converted_from_f64: RawReal,
precision: u32,
backtrace: Backtrace,
},
#[error("the output value is invalid!")]
Output {
#[from]
source: ErrorsValidationRawReal<RawReal>,
},
}
#[derive(Debug, Error)]
pub enum ErrorsRawRealToInteger<RawReal: RawRealTrait, IntType: Integer> {
#[error("Value is not finite: {value}")]
NotFinite {
value: RawReal,
backtrace: Backtrace,
},
#[error("Value is not an integer: {value}")]
NotAnInteger {
value: RawReal,
backtrace: Backtrace,
},
#[error("Value {value} is out of range [{min}, {max}] for target integer type")]
OutOfRange {
value: RawReal,
min: IntType,
max: IntType,
backtrace: Backtrace,
},
}
#[inline(always)]
pub fn capture_backtrace() -> Backtrace {
#[cfg(feature = "backtrace")]
{
Backtrace::force_capture()
}
#[cfg(not(feature = "backtrace"))]
{
Backtrace::disabled()
}
}
#[inline(always)]
pub const fn is_backtrace_enabled() -> bool {
#[cfg(feature = "backtrace")]
{
true
}
#[cfg(not(feature = "backtrace"))]
{
false
}
}