Created
January 25, 2022 19:36
-
-
Save raj-pranav/000be584c93771d2fccbced55de29313 to your computer and use it in GitHub Desktop.
Operators in Solidity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.0; | |
uint constant T = 10; | |
contract Arithmetic_Operation { | |
uint x = 10; | |
uint y = 20; | |
int p = -5; | |
int q = 11; | |
// Addition : (both operands should be either uint `OR` int) | |
uint sum_1 = x + y; | |
int sum_2 = p + q; | |
// Subtraction : (both operands should be either uint `OR` int) | |
// uint public sub1 = y - x; -> this is not possible as result would be -10 (a int type) | |
uint sub1 = y - x; | |
int sub2 = p - q; | |
int Un = -q; // Applicable only on signed integer type : int | |
// Multiplication : (both operands should be either uint `OR` int) | |
uint mul_1 = x * y; | |
int mul_2 = p * q; | |
// Divison : (both operands should be either uint `OR` int) | |
uint div_1 = x / y; // div_1 = 0 | |
int div_2 = p / q; // div_2 = 0 | |
uint div_3 = (x+1)/4; // div_3 = 2 | |
// Modulo : Modulo operation outputs the remainder (both operands should be either uint `OR` int) | |
uint mod_1 = x % y; // mod_1 = 10 | |
int mod_2 = p % q; // mod_2 = -5 | |
// Exponent : (both operands should be either uint `OR` int) | |
uint exp_1 = x ** y; // exp_1 = 100000000000000000000 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment