mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
37 lines
785 B
Solidity
37 lines
785 B
Solidity
type Int is int;
|
|
using {sub as -, unsub as -} for Int global;
|
|
|
|
function sub(Int a, Int b) pure returns (Int) {
|
|
return Int.wrap((Int.unwrap(a) - Int.unwrap(b)) * 100);
|
|
}
|
|
|
|
function unsub(Int a) pure returns (Int) {
|
|
return Int.wrap(Int.unwrap(a) + 10);
|
|
}
|
|
|
|
function u(int x) pure suffix returns (Int) {
|
|
return Int.wrap(x + 1);
|
|
}
|
|
|
|
function u(Int x) pure suffix returns (Int) {
|
|
return Int.wrap(Int.unwrap(x) + 1);
|
|
}
|
|
|
|
contract C {
|
|
function testUnary() public pure returns (Int) {
|
|
return -2 u;
|
|
}
|
|
|
|
function testUnaryWithParens() public pure returns (Int) {
|
|
return -(2 u);
|
|
}
|
|
|
|
function testBinary() public pure returns (Int) {
|
|
return 4 u - 2 u;
|
|
}
|
|
}
|
|
// ----
|
|
// testUnary() -> 13
|
|
// testUnaryWithParens() -> 13
|
|
// testBinary() -> 200
|