mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update libraries.rst
add unchecked
This commit is contained in:
parent
6d6c9e6e4f
commit
997c014971
@ -132,7 +132,7 @@ custom types without the overhead of external function calls:
|
|||||||
.. code-block:: solidity
|
.. code-block:: solidity
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.8 <0.9.0;
|
pragma solidity >=0.8.0 <0.9.0;
|
||||||
|
|
||||||
struct bigint {
|
struct bigint {
|
||||||
uint[] limbs;
|
uint[] limbs;
|
||||||
@ -150,11 +150,14 @@ custom types without the overhead of external function calls:
|
|||||||
for (uint i = 0; i < r.limbs.length; ++i) {
|
for (uint i = 0; i < r.limbs.length; ++i) {
|
||||||
uint a = limb(_a, i);
|
uint a = limb(_a, i);
|
||||||
uint b = limb(_b, i);
|
uint b = limb(_b, i);
|
||||||
r.limbs[i] = a + b + carry;
|
unchecked {
|
||||||
if (a + b < a || (a + b == type(uint).max && carry > 0))
|
r.limbs[i] = a + b + carry;
|
||||||
carry = 1;
|
|
||||||
else
|
if (a + b < a || (a + b == type(uint).max && carry > 0))
|
||||||
carry = 0;
|
carry = 1;
|
||||||
|
else
|
||||||
|
carry = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (carry > 0) {
|
if (carry > 0) {
|
||||||
// too bad, we have to add a limb
|
// too bad, we have to add a limb
|
||||||
|
Loading…
Reference in New Issue
Block a user