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
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.8 <0.9.0;
|
||||
pragma solidity >=0.8.0 <0.9.0;
|
||||
|
||||
struct bigint {
|
||||
uint[] limbs;
|
||||
@ -150,11 +150,14 @@ custom types without the overhead of external function calls:
|
||||
for (uint i = 0; i < r.limbs.length; ++i) {
|
||||
uint a = limb(_a, i);
|
||||
uint b = limb(_b, i);
|
||||
r.limbs[i] = a + b + carry;
|
||||
if (a + b < a || (a + b == type(uint).max && carry > 0))
|
||||
carry = 1;
|
||||
else
|
||||
carry = 0;
|
||||
unchecked {
|
||||
r.limbs[i] = a + b + carry;
|
||||
|
||||
if (a + b < a || (a + b == type(uint).max && carry > 0))
|
||||
carry = 1;
|
||||
else
|
||||
carry = 0;
|
||||
}
|
||||
}
|
||||
if (carry > 0) {
|
||||
// too bad, we have to add a limb
|
||||
|
Loading…
Reference in New Issue
Block a user