UNPKG

hardlydifficult-eth

Version:

A collection of reusable contracts and Javascript helpers for Ethereum.

1,037 lines 647 kB
{ "contractName": "BigDiv", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.6.10+commit.00c0fcaf\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"Results may be off by 1 + 0.000001% for 2x1 calls and 2 + 0.00001% for 2x2 calls. Do not use if your contract expects very small result values to be accurate.\",\"methods\":{},\"stateVariables\":{\"MAX_BEFORE_SQUARE\":{\"details\":\"When multiplying 2 terms <= this value the result won't overflow\"},\"MAX_ERROR\":{\"details\":\"The max error target is off by 1 plus up to 0.000001% error for bigDiv2x1 and that `* 2` for bigDiv2x2\"},\"MAX_ERROR_BEFORE_DIV\":{\"details\":\"A larger error threshold to use when multiple rounding errors may apply\"},\"MAX_UINT\":{\"details\":\"The max possible value\"}},\"title\":\"Reduces the size of terms before multiplication, to avoid an overflow, and then restores the proper size after division.\"},\"userdoc\":{\"methods\":{},\"notice\":\"This effectively allows us to overflow values in the numerator and/or denominator of a fraction, so long as the end result does not overflow as well.\"}},\"settings\":{\"compilationTarget\":{\"project:/contracts/math/BigDiv.sol\":\"BigDiv\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":2000000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/math/SafeMath.sol\":{\"keccak256\":\"0xcc78a17dd88fa5a2edc60c8489e2f405c0913b377216a5b26b35656b2d0dab52\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://526dc85e1f9b9b45830e202568d267d93dde7a4fcccf4ad7798dadcd92304d3c\",\"dweb:/ipfs/QmaoXMB972J3cSDLtBq3xBo4jLwqD2uzXTwujtSPqkYVhR\"]},\"project:/contracts/math/BigDiv.sol\":{\"keccak256\":\"0x2b9464c57ca4ed472debc814d6d5ddea6fc63e7c932220b21bd85f43b68d3861\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://a9a1e15fb29e6985de6ee17002c3161aed478804a7e5c5d783a7dfbe7cf7454d\",\"dweb:/ipfs/QmWH4Loq4uujmJGryQGAPgR4r8yA1b99QwMo3dYkd29dEe\"]}},\"version\":1}", "bytecode": "0x60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220aee47ebf61458022aa0a42bb0b4471fafba67cd8870a9daf98c080f106f7c50f64736f6c634300060a0033", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220aee47ebf61458022aa0a42bb0b4471fafba67cd8870a9daf98c080f106f7c50f64736f6c634300060a0033", "immutableReferences": {}, "sourceMap": "587:6272:11:-:0;;;;;;;;;;;;;;;;;;;;;;;;;", "deployedSourceMap": "587:6272:11:-:0;;;;;;;;", "source": "// SPDX-License-Identifier: MIT\npragma solidity ^0.6.0;\n\n\nimport '@openzeppelin/contracts/math/SafeMath.sol';\n\n/**\n * @title Reduces the size of terms before multiplication, to avoid an overflow, and then\n * restores the proper size after division.\n * @notice This effectively allows us to overflow values in the numerator and/or denominator\n * of a fraction, so long as the end result does not overflow as well.\n * @dev Results may be off by 1 + 0.000001% for 2x1 calls and 2 + 0.00001% for 2x2 calls.\n * Do not use if your contract expects very small result values to be accurate.\n */\nlibrary BigDiv\n{\n using SafeMath for uint256;\n\n /// @dev The max possible value\n uint256 private constant MAX_UINT = 2**256 - 1;\n\n /// @dev When multiplying 2 terms <= this value the result won't overflow\n uint256 private constant MAX_BEFORE_SQUARE = 2**128 - 1;\n\n /// @dev The max error target is off by 1 plus up to 0.000001% error\n /// for bigDiv2x1 and that `* 2` for bigDiv2x2\n uint256 private constant MAX_ERROR = 100000000;\n\n /// @dev A larger error threshold to use when multiple rounding errors may apply\n uint256 private constant MAX_ERROR_BEFORE_DIV = MAX_ERROR * 2;\n\n /**\n * @notice Returns the approx result of `a * b / d` so long as the result is <= MAX_UINT\n * @param _numA the first numerator term\n * @param _numB the second numerator term\n * @param _den the denominator\n * @return the approx result with up to off by 1 + MAX_ERROR, rounding down if needed\n */\n function bigDiv2x1(\n uint256 _numA,\n uint256 _numB,\n uint256 _den\n ) internal pure\n returns(uint256)\n {\n if(_numA == 0 || _numB == 0)\n {\n // would div by 0 or underflow if we don't special case 0\n return 0;\n }\n\n uint256 value;\n\n if(MAX_UINT / _numA >= _numB)\n {\n // a*b does not overflow, return exact math\n value = _numA * _numB;\n value /= _den;\n return value;\n }\n\n // Sort numerators\n uint256 numMax = _numB;\n uint256 numMin = _numA;\n if(_numA > _numB)\n {\n numMax = _numA;\n numMin = _numB;\n }\n\n value = numMax / _den;\n if(value > MAX_ERROR)\n {\n // _den is small enough to be MAX_ERROR or better w/o a factor\n value = value.mul(numMin);\n return value;\n }\n\n // formula = ((a / f) * b) / (d / f)\n // factor >= a / sqrt(MAX) * (b / sqrt(MAX))\n uint256 factor = numMin - 1;\n factor /= MAX_BEFORE_SQUARE;\n factor += 1;\n uint256 temp = numMax - 1;\n temp /= MAX_BEFORE_SQUARE;\n temp += 1;\n if(MAX_UINT / factor >= temp)\n {\n factor *= temp;\n value = numMax / factor;\n if(value > MAX_ERROR_BEFORE_DIV)\n {\n value = value.mul(numMin);\n temp = _den - 1;\n temp /= factor;\n temp = temp.add(1);\n value /= temp;\n return value;\n }\n }\n\n // formula: (a / (d / f)) * (b / f)\n // factor: b / sqrt(MAX)\n factor = numMin - 1;\n factor /= MAX_BEFORE_SQUARE;\n factor += 1;\n value = numMin / factor;\n temp = _den - 1;\n temp /= factor;\n temp += 1;\n temp = numMax / temp;\n value = value.mul(temp);\n return value;\n }\n\n /**\n * @notice Returns the approx result of `a * b / d` so long as the result is <= MAX_UINT\n * @param _numA the first numerator term\n * @param _numB the second numerator term\n * @param _den the denominator\n * @return the approx result with up to off by 1 + MAX_ERROR, rounding down if needed\n * @dev roundUp is implemented by first rounding down and then adding the max error to the result\n */\n function bigDiv2x1RoundUp(\n uint256 _numA,\n uint256 _numB,\n uint256 _den\n ) internal pure\n returns(uint256)\n {\n // first get the rounded down result\n uint256 value = bigDiv2x1(_numA, _numB, _den);\n\n if(value == 0)\n {\n // when the value rounds down to 0, assume up to an off by 1 error\n return 1;\n }\n\n // round down has a max error of MAX_ERROR, add that to the result\n // for a round up error of <= MAX_ERROR\n uint256 temp = value - 1;\n temp /= MAX_ERROR;\n temp += 1;\n if(MAX_UINT - value < temp)\n {\n // value + error would overflow, return MAX\n return MAX_UINT;\n }\n\n value += temp;\n\n return value;\n }\n\n /**\n * @notice Returns the approx result of `a * b / (c * d)` so long as the result is <= MAX_UINT\n * @param _numA the first numerator term\n * @param _numB the second numerator term\n * @param _denA the first denominator term\n * @param _denB the second denominator term\n * @return the approx result with up to off by 2 + MAX_ERROR*10 error, rounding down if needed\n * @dev this uses bigDiv2x1 and adds additional rounding error so the max error of this\n * formula is larger\n */\n function bigDiv2x2(\n uint256 _numA,\n uint256 _numB,\n uint256 _denA,\n uint256 _denB\n ) internal pure\n returns (uint256)\n {\n if(MAX_UINT / _denA >= _denB)\n {\n // denA*denB does not overflow, use bigDiv2x1 instead\n return bigDiv2x1(_numA, _numB, _denA * _denB);\n }\n\n if(_numA == 0 || _numB == 0)\n {\n // would div by 0 or underflow if we don't special case 0\n return 0;\n }\n\n // Sort denominators\n uint256 denMax = _denB;\n uint256 denMin = _denA;\n if(_denA > _denB)\n {\n denMax = _denA;\n denMin = _denB;\n }\n\n uint256 value;\n\n if(MAX_UINT / _numA >= _numB)\n {\n // a*b does not overflow, use `a / d / c`\n value = _numA * _numB;\n value /= denMin;\n value /= denMax;\n return value;\n }\n\n // `ab / cd` where both `ab` and `cd` would overflow\n\n // Sort numerators\n uint256 numMax = _numB;\n uint256 numMin = _numA;\n if(_numA > _numB)\n {\n numMax = _numA;\n numMin = _numB;\n }\n\n // formula = (a/d) * b / c\n uint256 temp = numMax / denMin;\n if(temp > MAX_ERROR_BEFORE_DIV)\n {\n return bigDiv2x1(temp, numMin, denMax);\n }\n\n // formula: ((a/f) * b) / d then either * f / c or / c * f\n // factor >= a / sqrt(MAX) * (b / sqrt(MAX))\n uint256 factor = numMin - 1;\n factor /= MAX_BEFORE_SQUARE;\n factor += 1;\n temp = numMax - 1;\n temp /= MAX_BEFORE_SQUARE;\n temp += 1;\n if(MAX_UINT / factor >= temp)\n {\n factor *= temp;\n\n value = numMax / factor;\n if(value > MAX_ERROR_BEFORE_DIV)\n {\n value = value.mul(numMin);\n value /= denMin;\n if(value > 0 && MAX_UINT / value >= factor)\n {\n value *= factor;\n value /= denMax;\n return value;\n }\n }\n }\n\n // formula: (a/f) * b / ((c*d)/f)\n // factor >= c / sqrt(MAX) * (d / sqrt(MAX))\n factor = denMin;\n factor /= MAX_BEFORE_SQUARE;\n temp = denMax;\n // + 1 here prevents overflow of factor*temp\n temp /= MAX_BEFORE_SQUARE + 1;\n factor *= temp;\n return bigDiv2x1(numMax / factor, numMin, MAX_UINT);\n }\n}", "sourcePath": "/home/circleci/repo/contracts/math/BigDiv.sol", "ast": { "absolutePath": "project:/contracts/math/BigDiv.sol", "exportedSymbols": { "BigDiv": [ 2789 ] }, "id": 2790, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 2246, "literals": [ "solidity", "^", "0.6", ".0" ], "nodeType": "PragmaDirective", "src": "32:23:11" }, { "absolutePath": "@openzeppelin/contracts/math/SafeMath.sol", "file": "@openzeppelin/contracts/math/SafeMath.sol", "id": 2247, "nodeType": "ImportDirective", "scope": 2790, "sourceUnit": 355, "src": "58:51:11", "symbolAliases": [], "unitAlias": "" }, { "abstract": false, "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": { "id": 2248, "nodeType": "StructuredDocumentation", "src": "111:475:11", "text": " @title Reduces the size of terms before multiplication, to avoid an overflow, and then\n restores the proper size after division.\n @notice This effectively allows us to overflow values in the numerator and/or denominator\n of a fraction, so long as the end result does not overflow as well.\n @dev Results may be off by 1 + 0.000001% for 2x1 calls and 2 + 0.00001% for 2x2 calls.\n Do not use if your contract expects very small result values to be accurate." }, "fullyImplemented": true, "id": 2789, "linearizedBaseContracts": [ 2789 ], "name": "BigDiv", "nodeType": "ContractDefinition", "nodes": [ { "id": 2251, "libraryName": { "contractScope": null, "id": 2249, "name": "SafeMath", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 354, "src": "612:8:11", "typeDescriptions": { "typeIdentifier": "t_contract$_SafeMath_$354", "typeString": "library SafeMath" } }, "nodeType": "UsingForDirective", "src": "606:27:11", "typeName": { "id": 2250, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "625:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } }, { "constant": true, "documentation": { "id": 2252, "nodeType": "StructuredDocumentation", "src": "637:31:11", "text": "@dev The max possible value" }, "id": 2259, "mutability": "constant", "name": "MAX_UINT", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2789, "src": "671:46:11", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2253, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "671:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_rational_115792089237316195423570985008687907853269984665640564039457584007913129639935_by_1", "typeString": "int_const 1157...(70 digits omitted)...9935" }, "id": 2258, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_rational_115792089237316195423570985008687907853269984665640564039457584007913129639936_by_1", "typeString": "int_const 1157...(70 digits omitted)...9936" }, "id": 2256, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "hexValue": "32", "id": 2254, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "707:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "nodeType": "BinaryOperation", "operator": "**", "rightExpression": { "argumentTypes": null, "hexValue": "323536", "id": 2255, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "710:3:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_256_by_1", "typeString": "int_const 256" }, "value": "256" }, "src": "707:6:11", "typeDescriptions": { "typeIdentifier": "t_rational_115792089237316195423570985008687907853269984665640564039457584007913129639936_by_1", "typeString": "int_const 1157...(70 digits omitted)...9936" } }, "nodeType": "BinaryOperation", "operator": "-", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 2257, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "716:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "707:10:11", "typeDescriptions": { "typeIdentifier": "t_rational_115792089237316195423570985008687907853269984665640564039457584007913129639935_by_1", "typeString": "int_const 1157...(70 digits omitted)...9935" } }, "visibility": "private" }, { "constant": true, "documentation": { "id": 2260, "nodeType": "StructuredDocumentation", "src": "722:73:11", "text": "@dev When multiplying 2 terms <= this value the result won't overflow" }, "id": 2267, "mutability": "constant", "name": "MAX_BEFORE_SQUARE", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2789, "src": "798:55:11", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2261, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "798:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_rational_340282366920938463463374607431768211455_by_1", "typeString": "int_const 3402...(31 digits omitted)...1455" }, "id": 2266, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_rational_340282366920938463463374607431768211456_by_1", "typeString": "int_const 3402...(31 digits omitted)...1456" }, "id": 2264, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "hexValue": "32", "id": 2262, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "843:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "nodeType": "BinaryOperation", "operator": "**", "rightExpression": { "argumentTypes": null, "hexValue": "313238", "id": 2263, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "846:3:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_128_by_1", "typeString": "int_const 128" }, "value": "128" }, "src": "843:6:11", "typeDescriptions": { "typeIdentifier": "t_rational_340282366920938463463374607431768211456_by_1", "typeString": "int_const 3402...(31 digits omitted)...1456" } }, "nodeType": "BinaryOperation", "operator": "-", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 2265, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "852:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "843:10:11", "typeDescriptions": { "typeIdentifier": "t_rational_340282366920938463463374607431768211455_by_1", "typeString": "int_const 3402...(31 digits omitted)...1455" } }, "visibility": "private" }, { "constant": true, "documentation": { "id": 2268, "nodeType": "StructuredDocumentation", "src": "858:117:11", "text": "@dev The max error target is off by 1 plus up to 0.000001% error\n for bigDiv2x1 and that `* 2` for bigDiv2x2" }, "id": 2271, "mutability": "constant", "name": "MAX_ERROR", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2789, "src": "978:46:11", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2269, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "978:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "argumentTypes": null, "hexValue": "313030303030303030", "id": 2270, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1015:9:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_100000000_by_1", "typeString": "int_const 100000000" }, "value": "100000000" }, "visibility": "private" }, { "constant": true, "documentation": { "id": 2272, "nodeType": "StructuredDocumentation", "src": "1029:80:11", "text": "@dev A larger error threshold to use when multiple rounding errors may apply" }, "id": 2277, "mutability": "constant", "name": "MAX_ERROR_BEFORE_DIV", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2789, "src": "1112:61:11", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2273, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1112:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2276, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 2274, "name": "MAX_ERROR", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2271, "src": "1160:9:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "*", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 2275, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1172:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "1160:13:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "private" }, { "body": { "id": 2492, "nodeType": "Block", "src": "1605:1528:11", "statements": [ { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 2295, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2291, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 2289, "name": "_numA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2280, "src": "1614:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "==", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 2290, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1623:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "1614:10:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "||", "rightExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2294, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 2292, "name": "_numB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2282, "src": "1628:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "==", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 2293, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1637:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "1628:10:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "1614:24:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 2299, "nodeType": "IfStatement", "src": "1611:120:11", "trueBody": { "id": 2298, "nodeType": "Block", "src": "1644:87:11", "statements": [ { "expression": { "argumentTypes": null, "hexValue": "30", "id": 2296, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1723:1:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "functionReturnParameters": 2288, "id": 2297, "nodeType": "Return", "src": "1716:8:11" } ] } }, { "assignments": [ 2301 ], "declarations": [ { "constant": false, "id": 2301, "mutability": "mutable", "name": "value", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2492, "src": "1737:13:11", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2300, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1737:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 2302, "initialValue": null, "nodeType": "VariableDeclarationStatement", "src": "1737:13:11" }, { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2307, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2305, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 2303, "name": "MAX_UINT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2259, "src": "1760:8:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "id": 2304, "name": "_numA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2280, "src": "1771:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "1760:16:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": ">=", "rightExpression": { "argumentTypes": null, "id": 2306, "name": "_numB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2282, "src": "1780:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "1760:25:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 2321, "nodeType": "IfStatement", "src": "1757:161:11", "trueBody": { "id": 2320, "nodeType": "Block", "src": "1791:127:11", "statements": [ { "expression": { "argumentTypes": null, "id": 2312, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 2308, "name": "value", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2301, "src": "1849:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2311, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 2309, "name": "_numA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2280, "src": "1857:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "*", "rightExpression": { "argumentTypes": null, "id": 2310, "name": "_numB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2282, "src": "1865:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "1857:13:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "1849:21:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 2313, "nodeType": "ExpressionStatement", "src": "1849:21:11" }, { "expression": { "argumentTypes": null, "id": 2316, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 2314, "name": "value", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2301, "src": "1878:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "/=", "rightHandSide": { "argumentTypes": null, "id": 2315, "name": "_den", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2284, "src": "1887:4:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "1878:13:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 2317, "nodeType": "ExpressionStatement", "src": "1878:13:11" }, { "expression": { "argumentTypes": null, "id": 2318, "name": "value", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2301, "src": "1906:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "functionReturnParameters": 2288, "id": 2319, "nodeType": "Return", "src": "1899:12:11" } ] } }, { "assignments": [ 2323 ], "declarations": [ { "constant": false, "id": 2323, "mutability": "mutable", "name": "numMax", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2492, "src": "1947:14:11", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2322, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1947:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 2325, "initialValue": { "argumentTypes": null, "id": 2324, "name": "_numB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2282, "src": "1964:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "1947:22:11" }, { "assignments": [ 2327 ], "declarations": [ { "constant": false, "id": 2327, "mutability": "mutable", "name": "numMin", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2492, "src": "1975:14:11", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2326, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1975:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 2329, "initialValue": { "argumentTypes": null, "id": 2328, "name": "_numA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2280, "src": "1992:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "1975:22:11" }, { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 2332, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 2330, "name": "_numA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2280, "src": "2006:5:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "opera