I came across the following code
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
What is meaning of (int256)
in this line, and is there any possibility of overflow here? Or here:
magnitude = 2 ** 64
ethereum-classicoverflowsolidity
I came across the following code
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
What is meaning of (int256)
in this line, and is there any possibility of overflow here? Or here:
magnitude = 2 ** 64
Best Answer
An educated guess:
Since you did not provide the type of variable
payoutsTo_
, I believe that it is:The following attempt of assigning a
uint256
value to anint256
variable would not compile:Therefore, it is required to cast the value of
_dividends * magnitude
toint256
.Yes, the value of
int256(_dividends * magnitude)
will:2 ** (255 - 64) <= _dividends < 2 ** (256 - 64)
2 ** (256 - 64) < _dividends