use core::error::Error;
use core::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IbmFloatError {
NotANumber,
PositiveInfinity,
NegativeInfinity,
PositiveOverflow,
NegativeOverflow,
PositiveUnderflow,
NegativeUnderflow,
}
impl Display for IbmFloatError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
let msg = match self {
Self::NotANumber => "input is NaN, which has no IBM HFP encoding",
Self::PositiveInfinity => {
"input is positive infinity, which is not representable in IBM HFP"
}
Self::NegativeInfinity => {
"input is negative infinity, which is not representable in IBM HFP"
}
Self::PositiveOverflow => "input exceeds the IBM HFP positive maximum",
Self::NegativeOverflow => "input exceeds the IBM HFP negative minimum",
Self::PositiveUnderflow => {
"input is too small to represent in IBM HFP (positive underflow)"
}
Self::NegativeUnderflow => {
"input is too small to represent in IBM HFP (negative underflow)"
}
};
formatter.write_str(msg)
}
}
impl Error for IbmFloatError {}