Solidity modular
음수 모듈러 연산
Solidity 0.8 기준, 음수를 양수로 모듈러 연산하면 음수를 리턴한다. 예를 들어 Solidity에서 -6 % 4 = -2 이다.
다음은 각 부호별 모듈러 연산 결과값의 예시이다.
| Num | modular | result |
|---|---|---|
| 6 | 4 | 2 |
| 6 | -4 | 2 |
| -6 | 4 | -2 |
| -6 | -4 | -2 |
contract Test {
function test (int256 num, int256 mod) public view returns (int256){
return num % mod;
}
}tags: blockchain, smart contract, solidity