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

Simplify naming in i257 #244

Merged
merged 7 commits into from
Jan 23, 2024
Merged

Conversation

delaaxe
Copy link
Contributor

@delaaxe delaaxe commented Jan 18, 2024

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the new behavior?

While code like the following is eventually understandable, it isn't as clearly obvious as the proposed one:

Before:

fn foo(value: i257) {
  let mut x: u256 = 42;
  if value.sign == true {
    x += value.inner;
  }
}

After:

fn foo(value: i257) {
  let mut x: u256 = 42;
  if value.is_negative {
    x += value.abs;
  }
}

Does this introduce a breaking change?

  • Yes
  • No

Other information

@delaaxe delaaxe requested a review from 0xLucqs as a code owner January 18, 2024 16:17
@0xLucqs
Copy link
Collaborator

0xLucqs commented Jan 19, 2024

@shramee any opinion ?

@shramee
Copy link
Contributor

shramee commented Jan 20, 2024

Yeah, I think is_negative makes it clearer! ❤️

src/math/src/signed_u256.cairo Outdated Show resolved Hide resolved
@delaaxe
Copy link
Contributor Author

delaaxe commented Jan 22, 2024

If you're ok I'd also do

struct i257 {
    abs: u256,
    is_negative: bool,
}

instead of

struct i257 {
    is_negative: bool,
    abs: u256,
}

as it would make storage packing a bit more intuitive if ever needed

@0xLucqs 0xLucqs merged commit 9110447 into keep-starknet-strange:main Jan 23, 2024
3 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants