aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/format/mod.rs16
2 files changed, 12 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d1cf3be..72be383 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,3 +18,4 @@ radix_fmt = "1.0.0"
18lazy_static = "1.3.0" 18lazy_static = "1.3.0"
19directories = "2.0.1" 19directories = "2.0.1"
20regex = "1.1.7" 20regex = "1.1.7"
21num = "0.2"
diff --git a/src/format/mod.rs b/src/format/mod.rs
index baae301..2ba7ad9 100644
--- a/src/format/mod.rs
+++ b/src/format/mod.rs
@@ -1,9 +1,13 @@
1extern crate num;
2use num::{BigInt, FromPrimitive, ToPrimitive};
3
1use crate::CONFIGURATION; 4use crate::CONFIGURATION;
2use crate::error::{ 5use crate::error::{
3 CalcError, 6 CalcError,
4 Math 7 Math
5}; 8};
6 9
10
7pub fn autobalance_parens(input: &str) -> Result<String, CalcError> { 11pub fn autobalance_parens(input: &str) -> Result<String, CalcError> {
8 let mut balanced = String::from(input); 12 let mut balanced = String::from(input);
9 let mut left_parens = 0; 13 let mut left_parens = 0;
@@ -35,13 +39,15 @@ fn radix_fmt(number: f64, obase: usize) -> Result<String, CalcError> {
35 let table: Vec<char> = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect(); 39 let table: Vec<char> = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();
36 40
37 // format integral part of float 41 // format integral part of float
38 let mut integral = number.abs().trunc() as i64; 42 let mut integral = BigInt::from_f64(number.abs().trunc()).unwrap();
39 let mut obase_int = String::new(); 43 let mut obase_int = String::new();
40 while integral >= obase as i64 { 44 let obaseb = BigInt::from_usize(obase).unwrap();
41 obase_int.push(table[(integral % obase as i64) as usize]); 45
42 integral /= obase as i64; 46 while &integral >= &obaseb {
47 obase_int.push(table[(&integral % &obaseb).to_usize().unwrap()]);
48 integral /= &obaseb;
43 } 49 }
44 obase_int.push(table[integral as usize]); 50 obase_int.push(table[integral.to_usize().unwrap()]);
45 if number.is_sign_negative() { 51 if number.is_sign_negative() {
46 obase_int.push('-'); 52 obase_int.push('-');
47 } 53 }