add skeleton Q104.104 implementation
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
pragma solidity 0.5.12;
|
||||
|
||||
// mock fixed- or floating-point math
|
||||
library MOCK_Decimal {
|
||||
struct Decimal {
|
||||
uint256 data;
|
||||
}
|
||||
|
||||
function div(uint128 numerator, uint128 denominator) internal pure returns (Decimal memory) {
|
||||
return Decimal(numerator / denominator);
|
||||
}
|
||||
|
||||
function mul(Decimal memory a, uint128 b) internal pure returns (Decimal memory) {
|
||||
return Decimal(a.data * b);
|
||||
}
|
||||
|
||||
function add(Decimal memory a, Decimal memory b) internal pure returns (Decimal memory) {
|
||||
return Decimal(a.data + b.data);
|
||||
}
|
||||
}
|
||||
@ -15,4 +15,9 @@ library SafeMath256 {
|
||||
require(y <= uint128(-1), "downcast-128-overflow");
|
||||
z = uint128(y);
|
||||
}
|
||||
|
||||
function downcast32(uint256 y) internal pure returns (uint32 z) {
|
||||
require(y <= uint32(-1), "downcast-32-overflow");
|
||||
z = uint32(y);
|
||||
}
|
||||
}
|
||||
|
||||
17
contracts/libraries/UQ104x104.sol
Normal file
17
contracts/libraries/UQ104x104.sol
Normal file
@ -0,0 +1,17 @@
|
||||
pragma solidity 0.5.12;
|
||||
|
||||
// TODO this whole library is basically just a mock at the moment
|
||||
library UQ104x104 {
|
||||
uint208 constant Q104 = uint104(-1);
|
||||
|
||||
function encode(uint128 y) internal pure returns (uint208 z) {
|
||||
// require(y <= Q104, "encode-overflow");
|
||||
z = y * Q104;
|
||||
}
|
||||
function qmul(uint208 x, uint208 y) internal pure returns (uint208 z) {
|
||||
z = x * y / Q104;
|
||||
}
|
||||
function qdiv(uint208 x, uint208 y) internal pure returns (uint208 z) {
|
||||
z = x / y;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user