-
Notifications
You must be signed in to change notification settings - Fork 56
Re-adjust % to & operation #262
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
Open
JaceCear
wants to merge
4
commits into
main
Choose a base branch
from
screen_shake_adjust
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
05b204d
'% 2u' doesn't match in SA3, implying that this was always '& 0x1'.
JaceCear 5f37391
Merge branch 'main' into screen_shake_adjust
JaceCear df3c067
Merge branch 'main' into screen_shake_adjust
JaceCear b8bb59e
Merge branch 'main' into screen_shake_adjust
JaceCear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't & 1 be better?
0x1is like it's a flag?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhh... well, if it was
value % 16u, I'd write& 0xFas well, so this is kind of more consistent?And if it was a flag... we'd a flag macro, right? 😋
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't write
& 0xFif I knew the point of this code was to trigger every 16 increments, it would be easier to understand as& 15?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused why we're arguing about it.
There's hundreds of cases of this in the codebase already.
And I do not think I'd ever prefer to read a decimal value in a bit-operation over hex. 😅
That's just not intuitive, imo.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To your point, yes there are lots of cases in the code. I'm aiming to improve the cases where the number as a decimal makes more sense. I would likely re-write this as & 1 hence I'm feeding back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just personally don't find it being an improvement when using bitwise ops on decimals.
The one case I understand is for word-alignment (like
(value + (4-1)) & ~(4-1)) but those would usually take the base as a parameter in a macro, not be handwritten. 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the intention of this was % 2u, but they wrote it as & 1, so it does make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, with hex, you immediately know how many bits are being &-ed against.
Sure, it's easy with 1, 3 and 7, but for higher numbers you need to convert decimal numbers first (either in your head or via calc), which is less intuitive, I would say.
I also think, and that might be a bit "by the gut" so to speak, that if you have a decimal value, you're more likely to change it to something that is not a bit mask when you edit it, introducing bugs, unlike a hex value, where you can intuitively infer what it does and why you should not just change it e.g. from 15 to 16.