Address Details
contract
0xd9cE4209888cfDfEb7c3d6e2CA34eeb06272284D
- Contract Name
- FixidityLib
- Creator
- 0xe23a4c–2b2dee at 0x25325a–4da0cd
- Balance
- 0 CELO ( )
- Locked CELO Balance
- 0.00 CELO
- Voting CELO Balance
- 0.00 CELO
- Pending Unlocked Gold
- 0.00 CELO
- Tokens
-
Fetching tokens...
- Transactions
- 0 Transactions
- Transfers
- 0 Transfers
- Gas Used
- Fetching gas used...
- Last Balance Update
- 2885
- Contract name:
- FixidityLib
- Optimization enabled
- false
- Compiler version
- v0.5.8+commit.23d335f2
- Verified at
- 2020-04-22T22:49:04.332488Z
Contract source code
pragma solidity ^0.5.0; library FixidityLib { struct Fraction { uint256 value; } function digits() internal pure returns (uint8) { return 24; } uint256 private constant FIXED1_UINT = 1000000000000000000000000; function fixed1() internal pure returns (Fraction memory) { return Fraction(FIXED1_UINT); } function wrap(uint256 x) internal pure returns (Fraction memory) { return Fraction(x); } function unwrap(Fraction memory x) internal pure returns (uint256) { return x.value; } function mulPrecision() internal pure returns (uint256) { return 1000000000000; } function maxNewFixed() internal pure returns (uint256) { return 115792089237316195423570985008687907853269984665640564; } function newFixed(uint256 x) internal pure returns (Fraction memory) { require(x <= maxNewFixed(), "can't create fixidity number larger than maxNewFixed()"); return Fraction(x * FIXED1_UINT); } function fromFixed(Fraction memory x) internal pure returns (uint256) { return x.value / FIXED1_UINT; } function newFixedFraction(uint256 numerator, uint256 denominator) internal pure returns (Fraction memory) { Fraction memory convertedNumerator = newFixed(numerator); Fraction memory convertedDenominator = newFixed(denominator); return divide(convertedNumerator, convertedDenominator); } function integer(Fraction memory x) internal pure returns (Fraction memory) { return Fraction((x.value / FIXED1_UINT) * FIXED1_UINT); } function fractional(Fraction memory x) internal pure returns (Fraction memory) { return Fraction(x.value - (x.value / FIXED1_UINT) * FIXED1_UINT); } function add(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) { uint256 z = x.value + y.value; require(z >= x.value, "add overflow detected"); return Fraction(z); } function subtract(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) { require(x.value >= y.value, "substraction underflow detected"); return Fraction(x.value - y.value); } function multiply(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) { if (x.value == 0 || y.value == 0) return Fraction(0); if (y.value == FIXED1_UINT) return x; if (x.value == FIXED1_UINT) return y; uint256 x1 = integer(x).value / FIXED1_UINT; uint256 x2 = fractional(x).value; uint256 y1 = integer(y).value / FIXED1_UINT; uint256 y2 = fractional(y).value; uint256 x1y1 = x1 * y1; if (x1 != 0) require(x1y1 / x1 == y1, "overflow x1y1 detected"); uint256 fixed_x1y1 = x1y1 * FIXED1_UINT; if (x1y1 != 0) require(fixed_x1y1 / x1y1 == FIXED1_UINT, "overflow x1y1 * fixed1 detected"); x1y1 = fixed_x1y1; uint256 x2y1 = x2 * y1; if (x2 != 0) require(x2y1 / x2 == y1, "overflow x2y1 detected"); uint256 x1y2 = x1 * y2; if (x1 != 0) require(x1y2 / x1 == y2, "overflow x1y2 detected"); x2 = x2 / mulPrecision(); y2 = y2 / mulPrecision(); uint256 x2y2 = x2 * y2; if (x2 != 0) require(x2y2 / x2 == y2, "overflow x2y2 detected"); Fraction memory result = Fraction(x1y1); result = add(result, Fraction(x2y1)); result = add(result, Fraction(x1y2)); result = add(result, Fraction(x2y2)); return result; } function reciprocal(Fraction memory x) internal pure returns (Fraction memory) { require(x.value != 0, "can't call reciprocal(0)"); return Fraction((FIXED1_UINT * FIXED1_UINT) / x.value); } function divide(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) { require(y.value != 0, "can't divide by 0"); uint256 X = x.value * FIXED1_UINT; require(X / FIXED1_UINT == x.value, "overflow at divide"); return Fraction(X / y.value); } function gt(Fraction memory x, Fraction memory y) internal pure returns (bool) { return x.value > y.value; } function gte(Fraction memory x, Fraction memory y) internal pure returns (bool) { return x.value >= y.value; } function lt(Fraction memory x, Fraction memory y) internal pure returns (bool) { return x.value < y.value; } function lte(Fraction memory x, Fraction memory y) internal pure returns (bool) { return x.value <= y.value; } function equals(Fraction memory x, Fraction memory y) internal pure returns (bool) { return x.value == y.value; } function isProperFraction(Fraction memory x) internal pure returns (bool) { return lte(x, fixed1()); } }
Contract ABI
[]
Contract Creation Code
0x604c6023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea165627a7a72305820d5c2ac341c7509406975c23fbf551efeaa4b750d4bbb89bb7356334ed275cbeb0029
Deployed ByteCode
0x73d9ce4209888cfdfeb7c3d6e2ca34eeb06272284d30146080604052600080fdfea165627a7a72305820d5c2ac341c7509406975c23fbf551efeaa4b750d4bbb89bb7356334ed275cbeb0029