pub enum Error {
Overflow(Option<i32>),
Underflow(Option<i32>),
DivByZero,
Reserved,
InvalidStr(String),
}
Expand description
§VAX floating-point errors
§Examples
use vax_floating::{FFloating, Error, Result};
use std::str::FromStr;
const ZERO: FFloating = FFloating::from_u8(0);
const TWO: FFloating = FFloating::from_u8(2);
// Failures return a reserved type with the error encoded.
let div_by_zero = TWO / ZERO;
let overflow = FFloating::MAX * TWO;
let underflow = FFloating::MIN_POSITIVE / TWO;
// You can convert a reserved value to the matching error.
assert_eq!(<Result<FFloating>>::from(div_by_zero), Err(Error::DivByZero));
assert_eq!(<Result<FFloating>>::from(overflow),
Err(Error::Overflow(Some(FFloating::MAX_EXP+1))));
assert_eq!(<Result<FFloating>>::from(underflow),
Err(Error::Underflow(Some(FFloating::MIN_EXP-1))));
assert_eq!(FFloating::from_str("0.0.0"), Err(Error::InvalidStr("0.0.0".to_string())));
Variants§
Overflow(Option<i32>)
Exponent too large for floating-point type.
Underflow(Option<i32>)
Exponent too small for floating-point type.
DivByZero
Set as the result of a division operation where the denominator is zero.
If converted into a Rust floating-point type, this will be converted into an Infinity
value. For
VAX floating-point types, it will be converted to the Reserved value (negative zero).
Reserved
VAX floating point numbers encoded with a negative zero trigger a reserved operand fault.
If converted into a Rust floating-point type, this will be converted into a NaN
value. For
VAX floating-point types, it will be converted to the Reserved value (negative zero).
InvalidStr(String)
Invalid string passed to from_str
or from_ascii
.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
impl Eq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more