-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Fixed point types #409
Comments
Some notes:
also this should work: what happens currently with add test about signed mod with rational constants (should behave identical to SMOD opcode) |
signed mod as in a modulus operation with signed rational constants? |
yes - and fixed point |
alright. I'll get on that. Crafting tests. Working on some fixes. And then it's onto the actual compilation. |
so couple of things. I got your first one working.
The second two in the examples you laid out, based on how we defined implicit conversion are currently impossible. 0.5 currently converts to ufixed0x8 and that does not convert with a uint128. uint(7) / 2 stays a uint256 after the division by 2 (it's truncating), and therefore cannot convert to ufixed128x128. And no... 0.5 * uint(7) is not the same as uint(7)/2....one is a ufixed0x8 and the other is dividing by an integer....kind of confusing....I'm thinking we may need to fix this up. Open to all suggestions....the only thing I can think up right now is to create a class atop integer type and fixed point and make it a super class of some kind... |
We decided to rather denote decimal places instead of "number of bits after the comma" to reduce confusion among users. This means that The type |
@chriseth do we still want to allow users to fully extend the decimal range so that it can be fixed0x32 (I believe that's the full amount that it could take in but may be wrong). |
@VoR0220 note that the 0 is the total amount of bits in the type. The drawback of using decimals is that you cannot force the value to be between 0 and 1 anymore (because that does not fit the decimal range). |
@chriseth so in other words it HAS to have an integer portion now...That's fine by me. The range and precisions seriously diminishes after 128 bits in fixed point either way. |
Sure. First we let: totalSupply = total # of tickets Then we calculate the exit fee: exitFee = (remainingTime / prizePeriodSeconds) * (balance / totalSupply) * previousPrize |
For me, forbidding multiplication of wide types makes the whole idea quite useless. I would prefer compiler to automatically apply different strategies for different types and even different values. For example, when combined bit-widths of both arguments do not exceed 2^256-1, naive approach could be used:
Otherwise, if
Probably, |
I love this idea. It would give us a lot more headroom over scaling the values. |
512-bit is not something we need to have in the first iteration of this. |
Yes, but overflow semantic should not change after the initial release, otherwise it will be a mess. Another option (the one I would prefer) is to include only literals, assignments, comparisons, ABI encode/decode, and reinterpret casts into the initial release of the feature in compiler, and leave arithmetic and conversion operations to be implemented in libraries, as there is no single “right” implementation for them. |
Revisited the nice summary from the OZ forums this Monday, and discussed some of this on Gitter. My current impression is that we should split this up into two phases (this was mentioned in the OZ forums too):
Even if we decide to move some operators into the compiler later on, I would argue that features like sqrt/pow/etc should stay in the stdlib. |
Sounds like a good first milestone, so I would say let's do this! One important point: Conversion from non-integer literals should also be part of the first milestone. |
Test ideas: check that e.g |
@chriseth What's the current status considering it's back in the icebox? |
@gorgos we are not convinced about implementing these types and the corresponding operations since there is no canonical implementation. Existing implementations are vastly different. Binary v/s decimals. 512 bit multiplication v/s reverting on shadow overflow. Differences in rounding etc. Currently, we want users to be able to implement this convinently using user defined value types and custom operators for it. |
@hrkrshnn It seems there is a chicken and egg problem: OpenZeppelin/openzeppelin-contracts#2265 (comment) My suggestion about how this problem could be solved is that at stage one Solidity could implement a fixed-point type natively (probably several such types, it there is no definite winner among candidates) but don't implement arithmetic operations on such type, leaving operations for libraries. So, what Solidity should do at stage one: choose type name and allow declaring variables/arguments etc of such type, choose type semantics, binary representation and ABI encoding, add support for fractional literals translated to the new type, implement operators |
With the introduction of user defined value types I no longer think it's necessary for Solidity to implement a fixed point type. Standardization of this type could (should?) happen as an EIP. |
That's pretty much the status of this, yes - we're working towards allowing customly defined operators on user-defined types which will allow for a full implementation of fixed point types on the user side which can then, for example, be standardized as an EIP or we may also suggest a standard implementation in a compiler-integrated standard library. |
Custom type + custom operations on that type wouldn't solve the problem, as it is not possible to introduce convenient literals this way, however without literals fixed point code will remain unreadable. I believe, that nowadays decimal fixed-point formats prevail over binary fixed-point and floating-point formats solely because Solidity kind of support decimals fixed-point literals in the form |
Literals will be part of the complete user-defined type construct. |
https://www.pivotaltracker.com/story/show/81779716
TODO:
The text was updated successfully, but these errors were encountered: