Merge pull request #11683 from GuLiPing-Hz/patch-1

[Docs] Add `unchecked` to fix reverting `BigInt` example in `libraries.rst`
This commit is contained in:
Harikrishnan Mulackal 2021-07-26 14:02:40 +02:00 committed by GitHub
commit 8f6c6eec27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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