print rationals that are integers as integers (#663)

This commit is contained in:
Mark Thom
2022-03-09 21:24:16 -07:00
parent d83b32a200
commit eace0d9b37
3 changed files with 13 additions and 8 deletions

4
Cargo.lock generated
View File

@@ -1348,9 +1348,9 @@ dependencies = [
[[package]] [[package]]
name = "rug" name = "rug"
version = "1.13.0" version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee0c6e98de59509e62e09f3456b23cebb75dad21928882016f169bb628843459" checksum = "6ac804305677221f4c82469fd7eb8bfe00dd01420aa191197cb87d738520feef"
dependencies = [ dependencies = [
"az", "az",
"gmp-mpfr-sys", "gmp-mpfr-sys",

View File

@@ -49,7 +49,7 @@ num-rug-adapter = { optional = true, path = "./crates/num-rug-adapter" }
ordered-float = "2.1.1" ordered-float = "2.1.1"
phf = { version = "0.9", features = ["macros"] } phf = { version = "0.9", features = ["macros"] }
ref_thread_local = "0.0.0" ref_thread_local = "0.0.0"
rug = { version = "1.12.0", optional = true } rug = { version = "1.15.0", optional = true }
rustyline = "9.0.0" rustyline = "9.0.0"
ring = "0.16.13" ring = "0.16.13"
ripemd160 = "0.8.0" ripemd160 = "0.8.0"

View File

@@ -961,8 +961,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
}); });
} }
Number::Rational(r) => { Number::Rational(r) => {
self.print_rational(r, add_brackets); self.print_rational(r);
return;
} }
n => { n => {
let output_str = format!("{}", n); let output_str = format!("{}", n);
@@ -993,11 +992,17 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
} }
} }
fn print_rational(&mut self, r: TypedArenaPtr<Rational>, add_brackets: bool) { fn print_rational(&mut self, r: TypedArenaPtr<Rational>) {
match self.op_dir.get(&(atom!("rdiv"), Fixity::In)) { match self.op_dir.get(&(atom!("rdiv"), Fixity::In)) {
Some(op_desc) => { Some(op_desc) => {
if add_brackets { if r.is_integer() {
self.state_stack.push(TokenOrRedirect::Close); let output_str = format!("{}", r);
push_space_if_amb!(self, &output_str, {
append_str!(self, &output_str);
});
return;
} }
let rdiv_ct = atom!("rdiv"); let rdiv_ct = atom!("rdiv");