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

Add builtin function abs #2356

Merged
merged 4 commits into from
Apr 20, 2021

Conversation

iamdefinitelyahuman
Copy link
Contributor

What I did

Add abs as a builtin function to get the absolute value of an int256.

How I did it

Add Abs within vyper/functions/functions.py. The logic is fairly straightforward - the only possible overflow is with -2**255 where we end up with the same value, so I do a check that the result is != the original value.

How to verify it

Run the tests. I've added hypothesis tests to verify both the runtime and compile-time behaviour, including the happy path and the reverting path.

Cute Animal Picture

image

@iamdefinitelyahuman iamdefinitelyahuman merged commit 174f7e2 into vyperlang:master Apr 20, 2021
@iamdefinitelyahuman iamdefinitelyahuman deleted the feat/abs branch April 20, 2021 22:14
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

2 participants