-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBasicMath
More file actions
29 lines (26 loc) · 863 Bytes
/
BasicMath
File metadata and controls
29 lines (26 loc) · 863 Bytes
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BasicMath {
// تابع جمع کننده
function adder(uint _a, uint _b) public pure returns (uint sum, bool error) {
unchecked {
sum = _a + _b;
// بررسی overflow
if (sum < _a) {
return (0, true); // overflow رخ داده است
}
return (sum, false); // بدون خطا
}
}
// تابع تفریق کننده
function subtractor(uint _a, uint _b) public pure returns (uint difference, bool error) {
unchecked {
// بررسی underflow
if (_b > _a) {
return (0, true); // underflow رخ داده است
}
difference = _a - _b;
return (difference, false); // بدون خطا
}
}
}