Questions tagged [modulo]
The modulo (sometimes called modulus) operation finds the remainder of division of one number by another. It's represented by the percent ('%') character in Solidity and by the "mod" keyword in Yul (assembly).
3 questions
2
votes
1
answer
144
views
Can't understand this GCD algorithm
I was trying to get the GCD of two numbers. This function I saw on github works fine but I have a confusion here.
The function :
function _gcd(uint256 a, uint256 b) external pure returns (uint256) {...
3
votes
1
answer
153
views
Why use assembly for mod operation instead of %?
I'm trying to understand why assembly for this sum is required?
Why not use + and % ?
_structHash = keccak256(
abi.encode(
_blockhash,
totalAddresses,
...
2
votes
1
answer
944
views
Is the modulo operation cheaper in unchecked arithmetic?
The docs on Solidity v0.8.0 Breaking Changes mention that overflows are now checked by default:
Arithmetic operations revert on underflow and overflow. You can use unchecked { ... } to use the ...