logic fix
parent
ab04dcea5d
commit
29856381e5
13
src/main.rs
13
src/main.rs
|
@ -20,9 +20,15 @@ fn hex_float(h: f64) -> String {
|
||||||
h *= 16.0;
|
h *= 16.0;
|
||||||
e += 1;
|
e += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut h = h as usize;
|
let mut h = h as usize;
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
|
if e == 0 {
|
||||||
|
output.push('0');
|
||||||
|
output.push('.');
|
||||||
|
}
|
||||||
|
|
||||||
let mut num_divides = 0;
|
let mut num_divides = 0;
|
||||||
while h > 0 {
|
while h > 0 {
|
||||||
output.push(match h % 16 {
|
output.push(match h % 16 {
|
||||||
|
@ -51,11 +57,6 @@ fn hex_float(h: f64) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if e == 0 {
|
|
||||||
output.push('.');
|
|
||||||
output.push('0');
|
|
||||||
}
|
|
||||||
|
|
||||||
if neg {
|
if neg {
|
||||||
output.push('-');
|
output.push('-');
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,7 @@ fn hex_float(h: f64) -> String {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hex_float() {
|
fn test_hex_float() {
|
||||||
assert_eq!["1.8", hex_float(1.5)];
|
assert_eq!["1.8", hex_float(f64::MAX)];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn separate_units(n: usize, how_base: HowNumberBase) -> String {
|
fn separate_units(n: usize, how_base: HowNumberBase) -> String {
|
||||||
|
|
Loading…
Reference in New Issue