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
Merged

Conversation

@iamdefinitelyahuman
Copy link
Contributor

iamdefinitelyahuman commented Dec 28, 2019

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
7 checks passed
7 checks passed
lint
Details
mypy
Details
py36-core
Details
py37-core
Details
py38-core
Details
LGTM analysis: JavaScript No code changes detected
Details
LGTM analysis: Python No new or fixed alerts
Details
@iamdefinitelyahuman iamdefinitelyahuman deleted the iamdefinitelyahuman:unary-fixes branch Jan 2, 2020
decimal_divisor = Decimal('1e10')
min_decimal = (-2**127 + 1) / decimal_divisor
max_decimal = (2**127 - 1) / decimal_divisor
min_decimal = -2**127 + 1

This comment has been minimized.

Copy link
@charles-cooper

charles-cooper Jan 6, 2020

Collaborator

this should just be -2**127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.