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

Unary operations on literals #1791

Merged
merged 3 commits into from
Dec 30, 2019

Conversation

iamdefinitelyahuman
Copy link
Contributor

What I did

Fixed some issues with negating constants.

The following example was failing because bounds checks caught 2**127 as an overflow before applying the -:

@public
def foo() -> int128:
    return -2**127

The following example was also failing with a clamping error:

a: constant(decimal) = 1.1

@public
def foo() -> decimal:
    return -a

How I did it

When an unary operation is applied to a constant, return the negated value without applying bounds checks on the original value.

How to verify it

Run the tests. I added some new test cases to verify that the issue is fixed.

Cute Animal Picture

image

@fubuloubu fubuloubu merged commit 47cd159 into vyperlang:master Dec 30, 2019
@iamdefinitelyahuman iamdefinitelyahuman deleted the unary-fixes branch January 2, 2020 16:25
decimal_divisor = Decimal('1e10')
min_decimal = (-2**127 + 1) / decimal_divisor
max_decimal = (2**127 - 1) / decimal_divisor
min_decimal = -2**127 + 1
Copy link
Member

Choose a reason for hiding this comment

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

this should just be -2**127

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.

3 participants