Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
2db19e7a46 |
2 changed files with 3 additions and 5 deletions
|
|
@ -2,9 +2,7 @@ use rug::Float;
|
|||
|
||||
use crate::nodes::{self, Error};
|
||||
|
||||
pub const MAX_DIGITS: usize = 10;
|
||||
|
||||
pub fn pretty_eval(mut input: String) -> Result<String, Error> {
|
||||
pub fn pretty_eval(mut input: String, max_digits: usize) -> Result<String, Error> {
|
||||
// no need to remove the characters here,
|
||||
// as we ignore the them in all other logic already
|
||||
let should_add_back_alignment = input.contains('&');
|
||||
|
|
@ -21,7 +19,7 @@ pub fn pretty_eval(mut input: String) -> Result<String, Error> {
|
|||
let result = nodes::eval(&input)?;
|
||||
let display_digits =
|
||||
get_significant_digits(&result)
|
||||
.min(MAX_DIGITS)
|
||||
.min(max_digits)
|
||||
.max(if result >= 1000 || result < 1 {
|
||||
1
|
||||
} else if result >= 100 {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ fn main() -> ExitCode {
|
|||
}
|
||||
};
|
||||
|
||||
match formatting::pretty_eval(input) {
|
||||
match formatting::pretty_eval(input, 10) {
|
||||
Ok(s) => println!("{s}"),
|
||||
|
||||
Err(e) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue