-
-
Notifications
You must be signed in to change notification settings - Fork 808
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
Need support for integer division in Vyper #716
Comments
Potential solution: add optimization that |
@fubuloubu yes, was thinking the same, the only problem comes when it's a nested expression. |
That's why optimization is the right solution. If it's not simple to figure out, don't do the optimization! Positive confirmation. |
@fubuloubu why not use |
Because from an auditability perspective, it may be easy to miss that extra Vyper is ease of audit, not ease of writability. |
I think decimal numbers in a smart contract are a luxury. Ethereum is integer-based, and 99% of all use cases ever call for integers, not decimals. I think the best solution would be to disallow integers and decimals to co-mingle. decimal / decimal = decimal (decimal division) Alternatively, we could still have separate operators for integer and decimal division! decimal / decimal = decimal (decimal division) integer // integer = integer (integer division) decimal / integer = COMPILE TIME ERROR decimal // integer = COMPILE TIME ERROR In fact, I'd remove ALL implicit conversions. Operators should only ever operate on operands of the exact same type, and return the same type. If you need to add an int128 to a uint256, cast explicitly. If you need to divide a decimal with an integer, cast explicitly. |
You know, this is probably a stronger and simpler approach. It makes auditability the main goal, and it would be simpler to describe. No implict conversions at all. What difficulties exist with this approach? |
I don't see any issue beyond code becoming more verbose (which, for Vyper, is more a requirement than a problem). Existing code not compiling after the change should not be an issue since Vyper is still in alpha. |
As mentioned in #717 (comment), I think we should put the above suggestion (#716 (comment)) into a VIP. This means we drop support for integer / integer = decimal, floor and ceil remain decimal operators and any cross-type division is not supported forcing explicit conversion. |
Sounds good to me! |
Merge into #737 as a VIP, thanks ;) |
What's your issue about?
I noticed that a recent change Vyper where
/
returnsdecimal
instead ofint128
. However, if a developer do want to use integer division (int128 // int128), he/she has to usefloor
to do the conversion. However, this conversion can potentially waste gas because '/' will first multiply DECIMAL_DIVISOR andfloor
will divide DECIMAL_DIVISOR. On the other hand, EVM opcodeDIV
performs the integer division.How can it be fixed?
Introduce operator
//
for integer division and it can be directly translated to DIV opcode in EVM.Cute Animal Picture
The text was updated successfully, but these errors were encountered: