Skip to content

Commit

Permalink
fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelica-Schell committed Jun 24, 2024
1 parent 55ec390 commit b39837c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions data-conversion/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ struct Arguments {
fn main() {
let args: Arguments = argh::from_env();

convert(&args.from, &args.to, args.ftype, args.totype, args.exp, args.bits);
convert(
&args.from,
&args.to,
args.ftype,
args.totype,
args.exp,
args.bits,
);
}

/// Converts [filepath_get] from type [convert_from] to type
Expand Down Expand Up @@ -147,12 +154,12 @@ fn convert(
}
}
(NumType::Binary, NumType::Fixed) => {
if !bits{
if !bits {
for line in read_to_string(filepath_get).unwrap().lines() {
binary_to_fixed(line, &mut converted, exponent)
.expect("Failed to write fixed-point to file");
}
}else {
} else {
for line in read_to_string(filepath_get).unwrap().lines() {
binary_to_fixed_bit_slice(line, &mut converted, exponent)
.expect("Failed to write fixed-point to file");
Expand All @@ -165,7 +172,6 @@ fn convert(
convert_to.to_string()
),
}

eprintln!(
"Successfully converted from {} to {} in {}",
convert_from.to_string(),
Expand Down Expand Up @@ -468,11 +474,11 @@ fn binary_to_fixed_bit_slice(
filepath_send: &mut File,
exp_int: i32,
) -> io::Result<()> {

// Parse the binary string to an integer
let binary = i32::from_str_radix(binary_string, 2).expect("Bad binary value input");

// Get bitmask from exponent
let binary =
i32::from_str_radix(binary_string, 2).expect("Bad binary value input");

// Get bitmask from exponent
let shift_amount = -exp_int;
let int_mask = !((1 << shift_amount) - 1);
let frac_mask = (1 << shift_amount) - 1;
Expand All @@ -499,11 +505,11 @@ fn binary_to_fixed_bit_slice(
}

// Append the integer and fractional parts
let combined_binary_representation = format!("{}.{}", int_part_binary, frac_part_binary);
let combined_binary_representation =
format!("{}.{}", int_part_binary, frac_part_binary);

// Write the combined binary representation to the file
writeln!(filepath_send, "{}", combined_binary_representation)?;

Ok(())

}

0 comments on commit b39837c

Please sign in to comment.