Skip to content

Commit

Permalink
Merge pull request #1679 from iamdefinitelyahuman/sqrt-maxnum
Browse files Browse the repository at this point in the history
Avoid overflow on sqrt of Decimal upper bound
  • Loading branch information
fubuloubu committed Nov 5, 2019
2 parents 8e577b3 + f068990 commit 181c70d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/parser/types/numbers/test_sqrt.py
Expand Up @@ -142,6 +142,13 @@ def test(a: decimal) -> decimal:
return c


@pytest.mark.parametrize('value', [Decimal(0), Decimal(SizeLimits.MAXNUM)])
def test_sqrt_bounds(sqrt_contract, value):
vyper_sqrt = sqrt_contract.test(value)
actual_sqrt = decimal_sqrt(value)
assert vyper_sqrt == actual_sqrt


@hypothesis.given(
value=hypothesis.strategies.decimals(
min_value=Decimal(0),
Expand Down
2 changes: 1 addition & 1 deletion vyper/functions/functions.py
Expand Up @@ -1210,7 +1210,7 @@ def sqrt(expr, args, kwargs, context):
if x == 0.0:
z = 0.0
else:
z = (x + 1.0) / 2.0
z = x / 2.0 + 0.5
y: decimal = x
for i in range(256):
Expand Down

0 comments on commit 181c70d

Please sign in to comment.