Properly make hex numbers
This commit is contained in:
parent
798539d219
commit
9ac596187d
1 changed files with 13 additions and 2 deletions
|
@ -87,8 +87,8 @@ impl NumberBuilder {
|
|||
fn place_value(digit: char) -> Option<f64> {
|
||||
match digit {
|
||||
'0' ... '9' => Some((digit as u32 - '0' as u32) as f64),
|
||||
'a' ... 'f' => Some((digit as u32 - 'a' as u32) as f64),
|
||||
'A' ... 'F' => Some((digit as u32 - 'A' as u32) as f64),
|
||||
'a' ... 'f' => Some((digit as u32 - 'a' as u32 + 10) as f64),
|
||||
'A' ... 'F' => Some((digit as u32 - 'A' as u32 + 10) as f64),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -158,4 +158,15 @@ mod tests {
|
|||
b.extend_decimal_value('4');
|
||||
assert_eq!(b.resolve().value, 5.34);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_hex() {
|
||||
let mut b = NumberBuilder::new();
|
||||
b.radix(Radix::Hex).extend_value('4');
|
||||
assert_eq!(b.resolve().value, 0x4 as f64);
|
||||
b.extend_value('A');
|
||||
assert_eq!(b.resolve().value, 0x4A as f64);
|
||||
b.extend_value('6');
|
||||
assert_eq!(b.resolve().value, 0x4A6 as f64);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue