mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 21:54:15 +00:00
Always consider floats as approx. when displayed
This commit is contained in:
parent
1b3109a263
commit
b5cec68217
1 changed files with 18 additions and 9 deletions
|
@ -628,15 +628,24 @@ impl Number {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn numeric_value(&self, base: u8) -> (Option<String>, Option<String>) {
|
pub fn numeric_value(&self, base: u8) -> (Option<String>, Option<String>) {
|
||||||
let (num, den) = self.0.to_rational();
|
match self.0 {
|
||||||
match to_string(&self.0, base) {
|
Num::Mpq(ref mpq) => {
|
||||||
(true, v) => (Some(v), None),
|
let num = mpq.get_num();
|
||||||
(false, v) => if {den > Mpz::from(1_000_000) ||
|
let den = mpq.get_den();
|
||||||
num > Mpz::from(1_000_000_000u64)} {
|
|
||||||
(None, Some(v))
|
match to_string(&self.0, base) {
|
||||||
} else {
|
(true, v) => (Some(v), None),
|
||||||
(Some(format!("{}/{}", num, den)), Some(v))
|
(false, v) => if {den > Mpz::from(1_000_000) ||
|
||||||
}
|
num > Mpz::from(1_000_000_000u64)} {
|
||||||
|
(None, Some(v))
|
||||||
|
} else {
|
||||||
|
(Some(format!("{}/{}", num, den)), Some(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Num::Float(_f) => {
|
||||||
|
(None, Some(to_string(&self.0, base).1))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue