Skip to content

Unary operations on literals#1791

Merged
fubuloubu merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:unary-fixes
Dec 30, 2019
Merged

Unary operations on literals#1791
fubuloubu merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:unary-fixes

Conversation

@iamdefinitelyahuman

Copy link
Copy Markdown
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
Copy Markdown
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