forked from bonsai/harakit
rpn(1): more improvements
This commit is contained in:
parent
cc53dab035
commit
b875aa1058
48
src/rpn.rs
48
src/rpn.rs
@ -120,14 +120,20 @@ impl Display for CalcType {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct EvaluationError {
|
struct EvaluationError {
|
||||||
message: String,
|
message: String,
|
||||||
code: ExitCode,
|
code: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StrError for EvaluationError {
|
||||||
|
fn strerror(&self) -> String {
|
||||||
|
self.message.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* I’m no math nerd but I want the highest possible approximation of 0.9
|
/* I’m no math nerd but I want the highest possible approximation of 0.9
|
||||||
* repeating and it seems this can give it to me */
|
* repeating and it seems this can give it to me */
|
||||||
const PRECISION_MOD: f64 = 0.9 + f64::EPSILON;
|
const PRECISION_MOD: f64 = 0.9 + f64::EPSILON;
|
||||||
|
|
||||||
fn err(argv0: &String, e: std::io::Error, code: Option<u8>) -> ExitCode {
|
fn err<T: StrError>(argv0: &String, e: &T, code: Option<u8>) -> ExitCode {
|
||||||
eprintln!("{}: {}", argv0, e.strerror());
|
eprintln!("{}: {}", argv0, e.strerror());
|
||||||
ExitCode::from(code.unwrap_or(1 /* unknown error */))
|
ExitCode::from(code.unwrap_or(1 /* unknown error */))
|
||||||
}
|
}
|
||||||