Skip to main content

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).

Filter by
Sorted by
Tagged with
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) {...
Zartaj Afser's user avatar
  • 5,305
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, ...
redigaffi's user avatar
  • 225
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 ...
Paul Razvan Berg's user avatar