Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit slice #2176

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Bit slice #2176

wants to merge 12 commits into from

Conversation

Angelica-Schell
Copy link
Contributor

Adding binary to fixed using bit slicing instead of multiplication. Use the -b flag to use this version instead

Copy link
Contributor

@bcarlet bcarlet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Angelica-Schell! I left a few comments on the new bit manipulation implementation; let me know if you'd like me to clarify anything.

@@ -106,6 +116,7 @@ fn convert(
convert_from: NumType,
convert_to: NumType,
exponent: i32,
bits: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're listing all the arguments in the doc comment, you should probably add bits. And incidentally, it looks like the descriptions of convert_{from,to} are out of date, as they refer to "references" that were removed.

11110100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that this test is being overwritten instead of adding a new one? (Or, if these tests aren't meant to be part of a permanent test suite, then they probably shouldn't be committed.)

/// # Panics
///
/// This function will panic if the input string cannot be parsed as a binary number.
fn binary_to_fixed_bit_slice(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missing something, but I was under the impression that it was the fixed_to_binary function where we were going to try a bit manipulation implementation? Having a second implementation of binary_to_fixed would still work for testing your benchmarking setup, though.

let frac = fractional_part;
for i in 0..shift_amount {
if (frac & (1 << i)) != 0 {
frac_part_value += 1.0 / (1 << (shift_amount - i)) as f64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the following comment is misguided, since I was originally thinking about bit manipulation in the context of fixed_to_binary. But I would sort of imagine that the goal for a bit manipulation version of binary_to_fixed would be to assemble the floating-point bit representation directly from the fixed-point bit representation and the exponent, in order to avoid doing any expensive floating-point operations. I.e., we would try to avoid doing these floating-point additions and divisions here?

@bcarlet bcarlet mentioned this pull request Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants