mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11225 from ethereum/index-safe-math
Added index for safemath in docs
This commit is contained in:
commit
a364e93580
@ -478,6 +478,7 @@ In any case, you will get a warning about the outer variable being shadowed.
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.. index:: ! safe math, safemath, checked, unchecked
|
||||||
.. _unchecked:
|
.. _unchecked:
|
||||||
|
|
||||||
Checked or Unchecked Arithmetic
|
Checked or Unchecked Arithmetic
|
||||||
@ -501,11 +502,11 @@ To obtain the previous behaviour, an ``unchecked`` block can be used:
|
|||||||
pragma solidity ^0.8.0;
|
pragma solidity ^0.8.0;
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a, uint b) pure public returns (uint) {
|
function f(uint a, uint b) pure public returns (uint) {
|
||||||
// This addition will wrap on underflow.
|
// This subtraction will wrap on underflow.
|
||||||
unchecked { return a - b; }
|
unchecked { return a - b; }
|
||||||
}
|
}
|
||||||
function g(uint a, uint b) pure public returns (uint) {
|
function g(uint a, uint b) pure public returns (uint) {
|
||||||
// This addition will revert on underflow.
|
// This subtraction will revert on underflow.
|
||||||
return a - b;
|
return a - b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user