hyperreal/problem.rs
1// We need to refer to these types in the documentation
2#[allow(unused_imports)]
3use crate::{Rational, Real};
4
5/// Problems when either parsing or attempting Arithmetic with [`Real`] numbers
6/// or when trying to make or convert to a [`Rational`].
7
8#[derive(Copy, Clone, Debug, PartialEq)]
9#[non_exhaustive]
10pub enum Problem {
11 /// Unspecified problem while parsing an expression
12 ParseError,
13 /// Tried to take the Square Root of a Negative, these values are Imaginary
14 SqrtNegative,
15 /// Tried to divide by Zero, also arises if attempting to make a fraction with a zero
16 /// denominator
17 DivideByZero,
18 /// The specified identifier in an expression was not found
19 NotFound,
20 /// The expression has too few parameters to evaluate
21 InsufficientParameters,
22 /// Tried to convert a floating point NaN, which has no equivalent
23 /// or evaluated the Logarithm of a non-positive value
24 /// or evaluated some other function outside its domain
25 NotANumber,
26 /// Tried to convert a floating point Infinity which has no equivalent
27 Infinity,
28 /// When parsing a fraction either the numerator or denominator weren't decimal digits
29 BadFraction,
30 /// When parsing a decimal there was non-digits on one or both sides of the decimal point
31 BadDecimal,
32 /// When parsing an integer there were non-digits in the text
33 BadInteger,
34 /// The integer was outside the range for the chosen type
35 OutOfRange,
36 /// The rational was not an integer
37 NotAnInteger,
38 /// Operation was rejected because it was likely to consume all available resources
39 Exhausted,
40 /// A checked operation could not prove that a value was non-zero.
41 ///
42 /// This is distinct from [`Problem::DivideByZero`]: exact-real algorithms
43 /// sometimes have enough structural information to reject definite zero,
44 /// but not enough to certify non-zero without unbounded refinement.
45 UnknownZero,
46}
47
48use std::fmt;
49
50impl fmt::Display for Problem {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 fmt::Debug::fmt(self, f)
53 }
54}
55
56impl std::error::Error for Problem {}