Start implementing parsing numbers from strings
Some checks failed
timw4mail/rusty-numbers/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2020-09-11 15:57:17 -04:00
parent d6b0825b9a
commit 19fa9bf6c7

View File

@ -128,7 +128,28 @@ impl BigInt {
/// Convert a `&str` or a `String` representing a number in the specified radix to a Bigint.
///
/// For radix 10, use the `from` associated function instead.
///
/// Radix must be between 1 and 36, inclusive, with radix higher
/// than 11 represented by A-Z
///
/// Only alphanumeric characters are considered, so exponents and
/// other forms are not parsed
pub fn from_str_radix<T: ToString>(s: T, radix: usize) -> BigInt {
let input = s.to_string();
// Convert each digit to it's decimal representation
let mut raw_digits: Vec<usize> = Vec::with_capacity(input.len());
for maybe_digit in input.chars() {
match maybe_digit.to_digit(radix as u32) {
Some(d) => raw_digits.push(d as usize),
None => continue,
}
}
// Calculate the decimal value by calculating the value
// of each place value
// In base 1, number of place values = total value
todo!();
}