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

bitWidth is wrong for -(power-of-two) #115

Open
wadetregaskis opened this issue Oct 9, 2023 · 0 comments
Open

bitWidth is wrong for -(power-of-two) #115

wadetregaskis opened this issue Oct 9, 2023 · 0 comments

Comments

@wadetregaskis
Copy link

wadetregaskis commented Oct 9, 2023

XCTAssertEqual(64, BigInt(Int64.min).bitWidth)

That fails, because bitWidth returns 65. It's not correctly handling the cases of 0b1 followed by some number of 0b0's, because with two's complement the magnitude of your minimum value is one higher than of your maximum value. Doing magnitude.bitWidth + 1 fails to account for this.

@wadetregaskis wadetregaskis changed the title bitWidth is wrong for -(power-of-two-plus-one) bitWidth is wrong for -(power-of-two) Oct 9, 2023
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

No branches or pull requests

1 participant