You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: minimize rounding that takes place (using gcd algorithm)let val = self.u64()* numerator / denominator;Uint64::from(val)
which is executed as (self.u64() * numerator) / denominator. This means that as soon as the multiplication overflows, the execution panics. This is an undesired behaviour because all of those:
In order to make this happen, we need to support a full multiplication that cannot overflow. For the Uint64 case this means multiplying two u64s into a u128 and for the Uint128 case this means multiplying two u128s into a 256 bit integer. The former can be done by casting to u128. The later is implemented e.g. in paritytech/parity-common#546. Maybe we can implement it manually though.
The text was updated successfully, but these errors were encountered:
Right now we use an implementation like this:
which is executed as
(self.u64() * numerator) / denominator
. This means that as soon as the multiplication overflows, the execution panics. This is an undesired behaviour because all of those:should return the same value.
In order to make this happen, we need to support a full multiplication that cannot overflow. For the Uint64 case this means multiplying two
u64
s into au128
and for the Uint128 case this means multiplying twou128
s into a 256 bit integer. The former can be done by casting to u128. The later is implemented e.g. in paritytech/parity-common#546. Maybe we can implement it manually though.The text was updated successfully, but these errors were encountered: