rpn(1): highest possible precision
This commit is contained in:
parent
942e284f93
commit
5debb9d954
@ -78,6 +78,10 @@ impl fmt::Display for EvaluationError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
const PRECISION_MOD: f64 = 0.9 + f64::EPSILON * 100.0;
|
||||||
|
|
||||||
// str_to_calc_type converts a string to an optional `CalcType`.
|
// str_to_calc_type converts a string to an optional `CalcType`.
|
||||||
fn str_to_calc_type(string: &str) -> Option<CalcType> {
|
fn str_to_calc_type(string: &str) -> Option<CalcType> {
|
||||||
let as_int = string.parse::<f64>();
|
let as_int = string.parse::<f64>();
|
||||||
@ -186,7 +190,7 @@ fn main() -> ExitCode {
|
|||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
let mut stack = VecDeque::new();
|
let mut stack = VecDeque::new();
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
let precision = (-f64::EPSILON.log10() * 0.999).ceil() as usize;
|
let precision = (-f64::EPSILON.log10() * PRECISION_MOD).ceil() as usize;
|
||||||
|
|
||||||
if argv.get(1).is_none() {
|
if argv.get(1).is_none() {
|
||||||
while let Ok(_) = stdin().read_line(&mut buf) {
|
while let Ok(_) = stdin().read_line(&mut buf) {
|
||||||
|
Loading…
Reference in New Issue
Block a user