Fix them rounding errors!

This commit is contained in:
Book-reader 2025-09-06 16:07:09 +12:00
parent 86c6c96909
commit b101b5af51

View file

@ -22,11 +22,12 @@ pub fn calculate(query: &str) -> Option<Calculation> {
let mut parser = Parser::new(Lexer::new(query)); let mut parser = Parser::new(Lexer::new(query));
let mut tree = parser.parse()?; let mut tree = parser.parse()?;
let res = tree.eval(); let res = tree.eval();
let res_float = f64::from_str(&format!("{}", res)).unwrap();
debug!("Calculation: {}", query); debug!("Calculation: {}", query);
// debug!("Tree: {:?}", tree); debug!("Tree: {:?}", tree);
debug!("Result: {}", res); debug!("Result: {:?}", res_float);
Some(Calculation {equation: query.to_string(), result: res.to_string()}) Some(Calculation {equation: query.to_string(), result: res_float.to_string()})
} }
// TODO: put into own crate with dependency astro-float = "0.9.2" so I can use more than BigFloat // TODO: put into own crate with dependency astro-float = "0.9.2" so I can use more than BigFloat