rpn(1): more improvements

This commit is contained in:
Emma Tebibyte 2024-08-24 19:00:01 -06:00
parent cc53dab035
commit b875aa1058
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -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()
}
} }
/* Im no math nerd but I want the highest possible approximation of 0.9 /* Im 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 */))
} }