-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.sol
56 lines (44 loc) · 1.62 KB
/
calculator.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract SimpleCalculator {
struct Calculation_Data {
string operation;
int256 result;
}
Calculation_Data public last_Calculation;
function add(int256 a, int256 b) public returns (int256) {
int256 result = a + b;
last_Calculation = Calculation_Data("Addition", result);
return result;
}
function subtract(int256 a, int256 b) public returns (int256) {
int256 result = a - b;
last_Calculation = Calculation_Data("Subtraction", result);
return result;
}
function multiply(int256 a, int256 b) public returns (int256) {
int256 result = a * b;
last_Calculation = Calculation_Data("Multiplication", result);
return result;
}
function divide(int256 a, int256 b) public returns (int256) {
require(b != 0, "Cannot divide by zero");
int256 result = a / b;
last_Calculation = Calculation_Data("Division", result);
return result;
}
function remainder(int256 a, int256 b) public returns (int256) {
require(b != 0, "Cannot divide by zero");
int256 result = a % b;
last_Calculation = Calculation_Data("Remainder", result);
return result;
}
function exponentiation(uint256 base, uint256 exponent) public returns (uint256) {
uint256 result = 1;
for(uint256 i = 0; i < exponent; i++) {
result *= base;
}
last_Calculation = Calculation_Data("Exponentiation", int256(result));
return result;
}
}