mirror of https://github.com/rm-dr/daisy
Error message edits
parent
c73bec0c13
commit
4eff57c273
|
@ -57,6 +57,26 @@ fn do_expression(
|
|||
)?;
|
||||
},
|
||||
|
||||
Err(EvalError::TooBig) => {
|
||||
write!(
|
||||
stdout, "\n {}{}Mathematical Error: {}Number too big{}\r\n\n",
|
||||
style::Bold,
|
||||
color::Fg(color::Red),
|
||||
style::Reset,
|
||||
color::Fg(color::Reset),
|
||||
)?;
|
||||
},
|
||||
|
||||
Err(EvalError::ZeroDivision) => {
|
||||
write!(
|
||||
stdout, "\n {}{}Mathematical Error: {}Division by zero{}\r\n\n",
|
||||
style::Bold,
|
||||
color::Fg(color::Red),
|
||||
style::Reset,
|
||||
color::Fg(color::Reset),
|
||||
)?;
|
||||
},
|
||||
|
||||
Err(EvalError::BadMath) => {
|
||||
write!(
|
||||
stdout, "\n {}{}Mathematical Error: {}Failed to evaluate expression{}\r\n\n",
|
||||
|
|
|
@ -8,5 +8,7 @@ pub use crate::tokens::operator::Operator;
|
|||
|
||||
pub enum EvalError {
|
||||
BadMath,
|
||||
TooBig,
|
||||
ZeroDivision,
|
||||
IncompatibleUnit
|
||||
}
|
|
@ -365,7 +365,7 @@ impl Operator{
|
|||
let args = args[0].as_number();
|
||||
|
||||
if let Token::Number(v) = args {
|
||||
if v.is_zero() { return Err(EvalError::BadMath); }
|
||||
if v.is_zero() { return Err(EvalError::ZeroDivision); }
|
||||
return Ok(Token::Number(
|
||||
Quantity::new_rational(1f64).unwrap()/v
|
||||
));
|
||||
|
@ -478,7 +478,7 @@ impl Operator{
|
|||
}
|
||||
|
||||
if !v.fract().is_zero() { return Err(EvalError::BadMath); }
|
||||
if v > Quantity::new_rational(50_000f64).unwrap() { return Err(EvalError::IncompatibleUnit); }
|
||||
if v > Quantity::new_rational(50_000f64).unwrap() { return Err(EvalError::TooBig); }
|
||||
|
||||
let mut prod = Quantity::new_rational(1f64).unwrap();
|
||||
let mut u = v.clone();
|
||||
|
|
Loading…
Reference in New Issue