Vyper: Literal division returns wrong result

Created on 24 Jun 2018  路  3Comments  路  Source: vyperlang/vyper

When I used vyper-run on this code:

@public
def test() -> decimal:
   return 5 / 2

I get the following output:

* Calling test()
- Returns:
'5'
- Logs:

When the expected result was 2.5 instead of 5.

After a few more tests with other numbers, it looks like the bug is that vyper-run prints out the original number before the division. So 7 / 3 returns 7. I am not sure yet if the problem is with vyper-run or Vyper itself.

There is a bug if the result is an int but is saved as a decimal.

For example, the same code as above but with 10 / 5 produces 2E-10. While it should either produce 2.0 or throw an error.

Cute Animal Picture

image

bug

Most helpful comment

This a bug with the literal simplification.

All 3 comments

This a bug with the literal simplification.

@zaq1tomo, go for it!

Our approach was to evaluate the constants in Python and set them to one number in our generated code output. It should match the data types being used, so 5/2 should floor to 2 but convert(5/2, 'fixed168x10') should convert to 2.5

I found the problem, parsing the return type was not working properly for literals.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacqueswww picture jacqueswww  路  3Comments

haydenadams picture haydenadams  路  3Comments

fubuloubu picture fubuloubu  路  3Comments

domrany64 picture domrany64  路  3Comments

nrryuya picture nrryuya  路  4Comments