mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-08 06:28:56 +01:00
Removed trailing zeroes from results.
This commit is contained in:
parent
e7cbbc45c2
commit
1056206d49
19
kalk_cli/Cargo.lock
generated
19
kalk_cli/Cargo.lock
generated
@ -134,6 +134,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"phf",
|
"phf",
|
||||||
"rug",
|
"rug",
|
||||||
|
"test-case",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -392,6 +393,18 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "test-case"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "199464148b42bcf3da8b2a56f6ee87ca68f47402496d1268849291ec9fb463c8"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-segmentation"
|
name = "unicode-segmentation"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
@ -416,6 +429,12 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
|
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "void"
|
name = "void"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
@ -4,13 +4,35 @@ use kalk::parser::{self};
|
|||||||
pub fn eval(parser: &mut parser::Context, input: &str) {
|
pub fn eval(parser: &mut parser::Context, input: &str) {
|
||||||
match parser::parse(parser, input, 53) {
|
match parser::parse(parser, input, 53) {
|
||||||
Ok(Some(result)) => {
|
Ok(Some(result)) => {
|
||||||
if result.clone().fract() == 0 {
|
if result.is_infinite() {
|
||||||
|
err("Too big to process.");
|
||||||
|
} else if result > 100_000_000 || result < -100_000_00 {
|
||||||
|
let sign = if result >= 0 { "" } else { "-" };
|
||||||
|
let (_, digits, exp) = result.to_sign_string_exp(10, None);
|
||||||
|
let value = format!(
|
||||||
|
"{}.{}",
|
||||||
|
digits[0..1].to_string(),
|
||||||
|
digits[1..].to_string().trim_end_matches('0')
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{}{}*10^{}", sign, value, exp.unwrap() - 1);
|
||||||
|
} else if result.clone().fract() == 0 {
|
||||||
println!("{}", result.to_integer().unwrap());
|
println!("{}", result.to_integer().unwrap());
|
||||||
} else {
|
} else {
|
||||||
println!("{}", result);
|
println!(
|
||||||
|
"{}",
|
||||||
|
result
|
||||||
|
.to_string()
|
||||||
|
.trim_end_matches('0')
|
||||||
|
.trim_end_matches('.')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => print!(""),
|
Ok(None) => print!(""),
|
||||||
Err(err) => println!("{}", Red.paint(err)),
|
Err(msg) => err(&msg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn err(msg: &str) {
|
||||||
|
println!("{}", Red.paint(msg));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user