diff --git a/test/libsolidity/semanticTests/fixedPoint/comparison.sol b/test/libsolidity/semanticTests/fixedPoint/comparison.sol new file mode 100644 index 000000000..8e90d2d4b --- /dev/null +++ b/test/libsolidity/semanticTests/fixedPoint/comparison.sol @@ -0,0 +1,22 @@ +contract C { + function test() public pure returns (bool) { + fixed64x4 x = fixed64x4(-1.12346789); + fixed64x4 y = -1.1235; + ufixed32x4 z = 1; + require(x == x); + require(x > y); + require(x >= y); + require(x != y); + require(y <= x); + require(!(x < y)); + require(y < z); + require(x < z); + require(z >= x); + require(z == z); + return true; + } +} +// ==== +// compileViaYul: also +// ---- +// test() -> true diff --git a/test/libsolidity/semanticTests/fixedPoint/comparison_rationals.sol b/test/libsolidity/semanticTests/fixedPoint/comparison_rationals.sol new file mode 100644 index 000000000..a34cbe11d --- /dev/null +++ b/test/libsolidity/semanticTests/fixedPoint/comparison_rationals.sol @@ -0,0 +1,12 @@ +contract C { + function test() public pure returns (bool) { + require(1/2 == 1/2); + require(fixed128x2(1/2 + 0.0000001) == 1/2); + require(fixed128x2(1/3) < 1/2); + return true; + } +} +// ==== +// compileViaYul: also +// ---- +// test() -> true \ No newline at end of file diff --git a/test/libsolidity/semanticTests/fixedPoint/conversion2.sol b/test/libsolidity/semanticTests/fixedPoint/conversion2.sol new file mode 100644 index 000000000..b80d0bfab --- /dev/null +++ b/test/libsolidity/semanticTests/fixedPoint/conversion2.sol @@ -0,0 +1,10 @@ +contract C { + function test() public pure returns (fixed64x3, fixed128x4, ufixed64x4) { + fixed64x4 x = fixed64x4(-1.12346789); + return (fixed64x3(x), fixed128x4(x), ufixed64x4(x)); + } +} +// ==== +// compileViaYul: also +// ---- +// test() -> -1.123, -1.1234, 1844674407370954.0382 diff --git a/test/libsolidity/semanticTests/fixedPoint/encodepacked.sol b/test/libsolidity/semanticTests/fixedPoint/encodepacked.sol new file mode 100644 index 000000000..3531cf3fb --- /dev/null +++ b/test/libsolidity/semanticTests/fixedPoint/encodepacked.sol @@ -0,0 +1,19 @@ +contract C { + function f() public pure returns (bytes memory) { + return abi.encodePacked( + 1.23, + fixed64x4(-1.234) + ); + } + function g() public pure returns (bytes memory) { + return abi.encode( + 1.23, + fixed64x4(-1.234) + ); + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> +// g() -> diff --git a/test/libsolidity/semanticTests/fixedPoint/getter.sol b/test/libsolidity/semanticTests/fixedPoint/getter.sol new file mode 100644 index 000000000..ebc0ae846 --- /dev/null +++ b/test/libsolidity/semanticTests/fixedPoint/getter.sol @@ -0,0 +1,13 @@ +contract C { + fixed64x4 public a = -2.123; + fixed64x4 public immutable b = -2.456; + mapping(uint => fixed64x4) public m; + constructor() { m[3] = 1.123; } +} +// ==== +// compileViaYul: also +// ---- +// a() -> -2.1230 +// b() -> -2.4560 +// m(uint256): 2 -> 0.0000 +// m(uint256): 3 -> 1.1230