UNPKG

arc_dx

Version:

A platform for building DAOs

926 lines (925 loc) 1.15 MB
{ "contractName": "RealMath", "abi": [], "bytecode": "0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146080604052600080fd00a165627a7a72305820929d3f88615a124d71f05faa18d29a3a65623e831061270d8ce914db06078d7c0029", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fd00a165627a7a72305820929d3f88615a124d71f05faa18d29a3a65623e831061270d8ce914db06078d7c0029", "sourceMap": "771:15930:42:-;;132:2:-1;166:7;155:9;146:7;137:37;252:7;246:14;243:1;238:23;232:4;229:33;270:1;265:20;;;;222:63;;265:20;274:9;222:63;;298:9;295:1;288:20;328:4;319:7;311:22;352:7;343;336:24", "deployedSourceMap": "771:15930:42:-;;;;;;;;", "source": "pragma solidity ^0.4.25;\n\n/**\n * RealMath: fixed-point math library, based on fractional and integer parts.\n * Using int256 as real216x40, which isn't in Solidity yet.\n * 40 fractional bits gets us down to 1E-12 precision, while still letting us\n * go up to galaxy scale counting in meters.\n * Internally uses the wider int256 for some math.\n *\n * Note that for addition, subtraction, and mod (%), you should just use the\n * built-in Solidity operators. Functions for these operations are not provided.\n *\n * Note that the fancy functions like sqrt, atan2, etc. aren't as accurate as\n * they should be. They are (hopefully) Good Enough for doing orbital mechanics\n * on block timescales in a game context, but they may not be good enough for\n * other applications.\n */\n\n\nlibrary RealMath {\n\n /**\n * How many total bits are there?\n */\n int256 constant REAL_BITS = 256;\n\n /**\n * How many fractional bits are there?\n */\n int256 constant REAL_FBITS = 40;\n\n /**\n * How many integer bits are there?\n */\n int256 constant REAL_IBITS = REAL_BITS - REAL_FBITS;\n\n /**\n * What's the first non-fractional bit\n */\n int256 constant REAL_ONE = int256(1) << REAL_FBITS;\n\n /**\n * What's the last fractional bit?\n */\n int256 constant REAL_HALF = REAL_ONE >> 1;\n\n /**\n * What's two? Two is pretty useful.\n */\n int256 constant REAL_TWO = REAL_ONE << 1;\n\n /**\n * And our logarithms are based on ln(2).\n */\n int256 constant REAL_LN_TWO = 762123384786;\n\n /**\n * It is also useful to have Pi around.\n */\n int256 constant REAL_PI = 3454217652358;\n\n /**\n * And half Pi, to save on divides.\n * TODO: That might not be how the compiler handles constants.\n */\n int256 constant REAL_HALF_PI = 1727108826179;\n\n /**\n * And two pi, which happens to be odd in its most accurate representation.\n */\n int256 constant REAL_TWO_PI = 6908435304715;\n\n /**\n * What's the sign bit?\n */\n int256 constant SIGN_MASK = int256(1) << 255;\n\n\n /**\n * Convert an integer to a real. Preserves sign.\n */\n function toReal(int216 ipart) internal pure returns (int256) {\n return int256(ipart) * REAL_ONE;\n }\n\n /**\n * Convert a real to an integer. Preserves sign.\n */\n function fromReal(int256 realValue) internal pure returns (int216) {\n return int216(realValue / REAL_ONE);\n }\n\n /**\n * Round a real to the nearest integral real value.\n */\n function round(int256 realValue) internal pure returns (int256) {\n // First, truncate.\n int216 ipart = fromReal(realValue);\n if ((fractionalBits(realValue) & (uint40(1) << (REAL_FBITS - 1))) > 0) {\n // High fractional bit is set. Round up.\n if (realValue < int256(0)) {\n // Rounding up for a negative number is rounding down.\n ipart -= 1;\n } else {\n ipart += 1;\n }\n }\n return toReal(ipart);\n }\n\n /**\n * Get the absolute value of a real. Just the same as abs on a normal int256.\n */\n function abs(int256 realValue) internal pure returns (int256) {\n if (realValue > 0) {\n return realValue;\n } else {\n return -realValue;\n }\n }\n\n /**\n * Returns the fractional bits of a real. Ignores the sign of the real.\n */\n function fractionalBits(int256 realValue) internal pure returns (uint40) {\n return uint40(abs(realValue) % REAL_ONE);\n }\n\n /**\n * Get the fractional part of a real, as a real. Ignores sign (so fpart(-0.5) is 0.5).\n */\n function fpart(int256 realValue) internal pure returns (int256) {\n // This gets the fractional part but strips the sign\n return abs(realValue) % REAL_ONE;\n }\n\n /**\n * Get the fractional part of a real, as a real. Respects sign (so fpartSigned(-0.5) is -0.5).\n */\n function fpartSigned(int256 realValue) internal pure returns (int256) {\n // This gets the fractional part but strips the sign\n int256 fractional = fpart(realValue);\n if (realValue < 0) {\n // Add the negative sign back in.\n return -fractional;\n } else {\n return fractional;\n }\n }\n\n /**\n * Get the integer part of a fixed point value.\n */\n function ipart(int256 realValue) internal pure returns (int256) {\n // Subtract out the fractional part to get the real part.\n return realValue - fpartSigned(realValue);\n }\n\n /**\n * Multiply one real by another. Truncates overflows.\n */\n function mul(int256 realA, int256 realB) internal pure returns (int256) {\n // When multiplying fixed point in x.y and z.w formats we get (x+z).(y+w) format.\n // So we just have to clip off the extra REAL_FBITS fractional bits.\n return int256((int256(realA) * int256(realB)) >> REAL_FBITS);\n }\n\n /**\n * Divide one real by another real. Truncates overflows.\n */\n function div(int256 realNumerator, int256 realDenominator) internal pure returns (int256) {\n // We use the reverse of the multiplication trick: convert numerator from\n // x.y to (x+z).(y+w) fixed point, then divide by denom in z.w fixed point.\n return int256((int256(realNumerator) * REAL_ONE) / int256(realDenominator));\n }\n\n /**\n * Create a real from a rational fraction.\n */\n function fraction(int216 numerator, int216 denominator) internal pure returns (int256) {\n return div(toReal(numerator), toReal(denominator));\n }\n\n // Now we have some fancy math things (like pow and trig stuff). This isn't\n // in the RealMath that was deployed with the original Macroverse\n // deployment, so it needs to be linked into your contract statically.\n\n /**\n * Raise a number to a positive integer power in O(log power) time.\n * See <https://stackoverflow.com/a/101613>\n */\n function ipow(int256 realBase, int216 exponent) internal pure returns (int256) {\n if (exponent < 0) {\n // Negative powers are not allowed here.\n revert();\n }\n\n int256 tempRealBase = realBase;\n int256 tempExponent = exponent;\n\n // Start with the 0th power\n int256 realResult = REAL_ONE;\n while (tempExponent != 0) {\n // While there are still bits set\n if ((tempExponent & 0x1) == 0x1) {\n // If the low bit is set, multiply in the (many-times-squared) base\n realResult = mul(realResult, tempRealBase);\n }\n // Shift off the low bit\n tempExponent = tempExponent >> 1;\n // Do the squaring\n tempRealBase = mul(tempRealBase, tempRealBase);\n }\n\n // Return the final result.\n return realResult;\n }\n\n /**\n * Zero all but the highest set bit of a number.\n * See <https://stackoverflow.com/a/53184>\n */\n function hibit(uint256 _val) internal pure returns (uint256) {\n // Set all the bits below the highest set bit\n uint256 val = _val;\n val |= (val >> 1);\n val |= (val >> 2);\n val |= (val >> 4);\n val |= (val >> 8);\n val |= (val >> 16);\n val |= (val >> 32);\n val |= (val >> 64);\n val |= (val >> 128);\n return val ^ (val >> 1);\n }\n\n /**\n * Given a number with one bit set, finds the index of that bit.\n */\n function findbit(uint256 val) internal pure returns (uint8 index) {\n index = 0;\n // We and the value with alternating bit patters of various pitches to find it.\n if (val & 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA != 0) {\n // Picth 1\n index |= 1;\n }\n if (val & 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC != 0) {\n // Pitch 2\n index |= 2;\n }\n if (val & 0xF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 != 0) {\n // Pitch 4\n index |= 4;\n }\n if (val & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 != 0) {\n // Pitch 8\n index |= 8;\n }\n if (val & 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 != 0) {\n // Pitch 16\n index |= 16;\n }\n if (val & 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000 != 0) {\n // Pitch 32\n index |= 32;\n }\n if (val & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000 != 0) {\n // Pitch 64\n index |= 64;\n }\n if (val & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000 != 0) {\n // Pitch 128\n index |= 128;\n }\n }\n\n /**\n * Shift realArg left or right until it is between 1 and 2. Return the\n * rescaled value, and the number of bits of right shift applied. Shift may be negative.\n *\n * Expresses realArg as realScaled * 2^shift, setting shift to put realArg between [1 and 2).\n *\n * Rejects 0 or negative arguments.\n */\n function rescale(int256 realArg) internal pure returns (int256 realScaled, int216 shift) {\n if (realArg <= 0) {\n // Not in domain!\n revert();\n }\n\n // Find the high bit\n int216 highBit = findbit(hibit(uint256(realArg)));\n\n // We'll shift so the high bit is the lowest non-fractional bit.\n shift = highBit - int216(REAL_FBITS);\n\n if (shift < 0) {\n // Shift left\n realScaled = realArg << -shift;\n } else if (shift >= 0) {\n // Shift right\n realScaled = realArg >> shift;\n }\n }\n\n /**\n * Calculate the natural log of a number. Rescales the input value and uses\n * the algorithm outlined at <https://math.stackexchange.com/a/977836> and\n * the ipow implementation.\n *\n * Lets you artificially limit the number of iterations.\n *\n * Note that it is potentially possible to get an un-converged value; lack\n * of convergence does not throw.\n */\n function lnLimited(int256 realArg, int maxIterations) internal pure returns (int256) {\n if (realArg <= 0) {\n // Outside of acceptable domain\n revert();\n }\n\n if (realArg == REAL_ONE) {\n // Handle this case specially because people will want exactly 0 and\n // not ~2^-39 ish.\n return 0;\n }\n\n // We know it's positive, so rescale it to be between [1 and 2)\n int256 realRescaled;\n int216 shift;\n (realRescaled, shift) = rescale(realArg);\n\n // Compute the argument to iterate on\n int256 realSeriesArg = div(realRescaled - REAL_ONE, realRescaled + REAL_ONE);\n\n // We will accumulate the result here\n int256 realSeriesResult = 0;\n\n for (int216 n = 0; n < maxIterations; n++) {\n // Compute term n of the series\n int256 realTerm = div(ipow(realSeriesArg, 2 * n + 1), toReal(2 * n + 1));\n // And add it in\n realSeriesResult += realTerm;\n if (realTerm == 0) {\n // We must have converged. Next term is too small to represent.\n break;\n }\n // If we somehow never converge I guess we will run out of gas\n }\n\n // Double it to account for the factor of 2 outside the sum\n realSeriesResult = mul(realSeriesResult, REAL_TWO);\n\n // Now compute and return the overall result\n return mul(toReal(shift), REAL_LN_TWO) + realSeriesResult;\n\n }\n\n /**\n * Calculate a natural logarithm with a sensible maximum iteration count to\n * wait until convergence. Note that it is potentially possible to get an\n * un-converged value; lack of convergence does not throw.\n */\n function ln(int256 realArg) internal pure returns (int256) {\n return lnLimited(realArg, 100);\n }\n\n /**\n * Calculate e^x. Uses the series given at\n * <http://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/exp.html>.\n *\n * Lets you artificially limit the number of iterations.\n *\n * Note that it is potentially possible to get an un-converged value; lack\n * of convergence does not throw.\n */\n function expLimited(int256 realArg, int maxIterations) internal pure returns (int256) {\n // We will accumulate the result here\n int256 realResult = 0;\n\n // We use this to save work computing terms\n int256 realTerm = REAL_ONE;\n\n for (int216 n = 0; n < maxIterations; n++) {\n // Add in the term\n realResult += realTerm;\n\n // Compute the next term\n realTerm = mul(realTerm, div(realArg, toReal(n + 1)));\n\n if (realTerm == 0) {\n // We must have converged. Next term is too small to represent.\n break;\n }\n // If we somehow never converge I guess we will run out of gas\n }\n\n // Return the result\n return realResult;\n\n }\n\n /**\n * Calculate e^x with a sensible maximum iteration count to wait until\n * convergence. Note that it is potentially possible to get an un-converged\n * value; lack of convergence does not throw.\n */\n function exp(int256 realArg) internal pure returns (int256) {\n return expLimited(realArg, 100);\n }\n\n /**\n * Raise any number to any power, except for negative bases to fractional powers.\n */\n function pow(int256 realBase, int256 realExponent) internal pure returns (int256) {\n if (realExponent == 0) {\n // Anything to the 0 is 1\n return REAL_ONE;\n }\n\n if (realBase == 0) {\n if (realExponent < 0) {\n // Outside of domain!\n revert();\n }\n // Otherwise it's 0\n return 0;\n }\n\n if (fpart(realExponent) == 0) {\n // Anything (even a negative base) is super easy to do to an integer power.\n\n if (realExponent > 0) {\n // Positive integer power is easy\n return ipow(realBase, fromReal(realExponent));\n } else {\n // Negative integer power is harder\n return div(REAL_ONE, ipow(realBase, fromReal(-realExponent)));\n }\n }\n\n if (realBase < 0) {\n // It's a negative base to a non-integer power.\n // In general pow(-x^y) is undefined, unless y is an int or some\n // weird rational-number-based relationship holds.\n revert();\n }\n\n // If it's not a special case, actually do it.\n return exp(mul(realExponent, ln(realBase)));\n }\n\n /**\n * Compute the square root of a number.\n */\n function sqrt(int256 realArg) internal pure returns (int256) {\n return pow(realArg, REAL_HALF);\n }\n\n /**\n * Compute the sin of a number to a certain number of Taylor series terms.\n */\n function sinLimited(int256 _realArg, int216 maxIterations) internal pure returns (int256) {\n // First bring the number into 0 to 2 pi\n // TODO: This will introduce an error for very large numbers, because the error in our Pi will compound.\n // But for actual reasonable angle values we should be fine.\n int256 realArg = _realArg;\n realArg = realArg % REAL_TWO_PI;\n\n int256 accumulator = REAL_ONE;\n\n // We sum from large to small iteration so that we can have higher powers in later terms\n for (int216 iteration = maxIterations - 1; iteration >= 0; iteration--) {\n accumulator = REAL_ONE - mul(div(mul(realArg, realArg), toReal((2 * iteration + 2) * (2 * iteration + 3))), accumulator);\n // We can't stop early; we need to make it to the first term.\n }\n\n return mul(realArg, accumulator);\n }\n\n /**\n * Calculate sin(x) with a sensible maximum iteration count to wait until\n * convergence.\n */\n function sin(int256 realArg) internal pure returns (int256) {\n return sinLimited(realArg, 15);\n }\n\n /**\n * Calculate cos(x).\n */\n function cos(int256 realArg) internal pure returns (int256) {\n return sin(realArg + REAL_HALF_PI);\n }\n\n /**\n * Calculate tan(x). May overflow for large results. May throw if tan(x)\n * would be infinite, or return an approximation, or overflow.\n */\n function tan(int256 realArg) internal pure returns (int256) {\n return div(sin(realArg), cos(realArg));\n }\n}\n", "sourcePath": "@daostack/infra/contracts/libs/RealMath.sol", "ast": { "absolutePath": "@daostack/infra/contracts/libs/RealMath.sol", "exportedSymbols": { "RealMath": [ 15770 ] }, "id": 15771, "nodeType": "SourceUnit", "nodes": [ { "id": 14787, "literals": [ "solidity", "^", "0.4", ".25" ], "nodeType": "PragmaDirective", "src": "0:24:42" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": "RealMath: fixed-point math library, based on fractional and integer parts.\nUsing int256 as real216x40, which isn't in Solidity yet.\n40 fractional bits gets us down to 1E-12 precision, while still letting us\ngo up to galaxy scale counting in meters.\nInternally uses the wider int256 for some math.\n * Note that for addition, subtraction, and mod (%), you should just use the\nbuilt-in Solidity operators. Functions for these operations are not provided.\n * Note that the fancy functions like sqrt, atan2, etc. aren't as accurate as\nthey should be. They are (hopefully) Good Enough for doing orbital mechanics\non block timescales in a game context, but they may not be good enough for\nother applications.", "fullyImplemented": true, "id": 15770, "linearizedBaseContracts": [ 15770 ], "name": "RealMath", "nodeType": "ContractDefinition", "nodes": [ { "constant": true, "id": 14790, "name": "REAL_BITS", "nodeType": "VariableDeclaration", "scope": 15770, "src": "849:31:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14788, "name": "int256", "nodeType": "ElementaryTypeName", "src": "849:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "hexValue": "323536", "id": 14789, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "877:3:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_256_by_1", "typeString": "int_const 256" }, "value": "256" }, "visibility": "internal" }, { "constant": true, "id": 14793, "name": "REAL_FBITS", "nodeType": "VariableDeclaration", "scope": 15770, "src": "946:31:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14791, "name": "int256", "nodeType": "ElementaryTypeName", "src": "946:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "hexValue": "3430", "id": 14792, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "975:2:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_40_by_1", "typeString": "int_const 40" }, "value": "40" }, "visibility": "internal" }, { "constant": true, "id": 14798, "name": "REAL_IBITS", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1040:51:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14794, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1040:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_int256", "typeString": "int256" }, "id": 14797, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 14795, "name": "REAL_BITS", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14790, "src": "1069:9:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "nodeType": "BinaryOperation", "operator": "-", "rightExpression": { "argumentTypes": null, "id": 14796, "name": "REAL_FBITS", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14793, "src": "1081:10:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "src": "1069:22:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "visibility": "internal" }, { "constant": true, "id": 14805, "name": "REAL_ONE", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1157:50:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14799, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1157:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_int256", "typeString": "int256" }, "id": 14804, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "31", "id": 14801, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1191:1:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" } ], "id": 14800, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "1184:6:42", "typeDescriptions": { "typeIdentifier": "t_type$_t_int256_$", "typeString": "type(int256)" }, "typeName": "int256" }, "id": 14802, "isConstant": false, "isLValue": false, "isPure": true, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1184:9:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "nodeType": "BinaryOperation", "operator": "<<", "rightExpression": { "argumentTypes": null, "id": 14803, "name": "REAL_FBITS", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14793, "src": "1197:10:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "src": "1184:23:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "visibility": "internal" }, { "constant": true, "id": 14810, "name": "REAL_HALF", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1269:41:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14806, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1269:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_int256", "typeString": "int256" }, "id": 14809, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 14807, "name": "REAL_ONE", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14805, "src": "1297:8:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "nodeType": "BinaryOperation", "operator": ">>", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 14808, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1309:1:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "1297:13:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "visibility": "internal" }, { "constant": true, "id": 14815, "name": "REAL_TWO", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1374:40:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14811, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1374:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_int256", "typeString": "int256" }, "id": 14814, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 14812, "name": "REAL_ONE", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14805, "src": "1401:8:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "nodeType": "BinaryOperation", "operator": "<<", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 14813, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1413:1:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "1401:13:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "visibility": "internal" }, { "constant": true, "id": 14818, "name": "REAL_LN_TWO", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1483:42:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14816, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1483:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "hexValue": "373632313233333834373836", "id": 14817, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1513:12:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_762123384786_by_1", "typeString": "int_const 762123384786" }, "value": "762123384786" }, "visibility": "internal" }, { "constant": true, "id": 14821, "name": "REAL_PI", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1592:39:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14819, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1592:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "hexValue": "33343534323137363532333538", "id": 14820, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1618:13:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_3454217652358_by_1", "typeString": "int_const 3454217652358" }, "value": "3454217652358" }, "visibility": "internal" }, { "constant": true, "id": 14824, "name": "REAL_HALF_PI", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1761:44:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14822, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1761:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "hexValue": "31373237313038383236313739", "id": 14823, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1792:13:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1727108826179_by_1", "typeString": "int_const 1727108826179" }, "value": "1727108826179" }, "visibility": "internal" }, { "constant": true, "id": 14827, "name": "REAL_TWO_PI", "nodeType": "VariableDeclaration", "scope": 15770, "src": "1908:43:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14825, "name": "int256", "nodeType": "ElementaryTypeName", "src": "1908:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "hexValue": "36393038343335333034373135", "id": 14826, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1938:13:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_6908435304715_by_1", "typeString": "int_const 6908435304715" }, "value": "6908435304715" }, "visibility": "internal" }, { "constant": true, "id": 14834, "name": "SIGN_MASK", "nodeType": "VariableDeclaration", "scope": 15770, "src": "2002:44:42", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14828, "name": "int256", "nodeType": "ElementaryTypeName", "src": "2002:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_int256", "typeString": "int256" }, "id": 14833, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "31", "id": 14830, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2037:1:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" } ], "id": 14829, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "2030:6:42", "typeDescriptions": { "typeIdentifier": "t_type$_t_int256_$", "typeString": "type(int256)" }, "typeName": "int256" }, "id": 14831, "isConstant": false, "isLValue": false, "isPure": true, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2030:9:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "nodeType": "BinaryOperation", "operator": "<<", "rightExpression": { "argumentTypes": null, "hexValue": "323535", "id": 14832, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2043:3:42", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_255_by_1", "typeString": "int_const 255" }, "value": "255" }, "src": "2030:16:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "visibility": "internal" }, { "body": { "id": 14847, "nodeType": "Block", "src": "2184:48:42", "statements": [ { "expression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_int256", "typeString": "int256" }, "id": 14845, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 14842, "name": "ipart", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14836, "src": "2208:5:42", "typeDescriptions": { "typeIdentifier": "t_int216", "typeString": "int216" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_int216", "typeString": "int216" } ], "id": 14841, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "2201:6:42", "typeDescriptions": { "typeIdentifier": "t_type$_t_int256_$", "typeString": "type(int256)" }, "typeName": "int256" }, "id": 14843, "isConstant": false, "isLValue": false, "isPure": false, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2201:13:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "nodeType": "BinaryOperation", "operator": "*", "rightExpression": { "argumentTypes": null, "id": 14844, "name": "REAL_ONE", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 14805, "src": "2217:8:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "src": "2201:24:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "functionReturnParameters": 14840, "id": 14846, "nodeType": "Return", "src": "2194:31:42" } ] }, "documentation": "Convert an integer to a real. Preserves sign.", "id": 14848, "implemented": true, "isConstructor": false, "isDeclaredConst": true, "modifiers": [], "name": "toReal", "nodeType": "FunctionDefinition", "parameters": { "id": 14837, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 14836, "name": "ipart", "nodeType": "VariableDeclaration", "scope": 14848, "src": "2139:12:42", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int216", "typeString": "int216" }, "typeName": { "id": 14835, "name": "int216", "nodeType": "ElementaryTypeName", "src": "2139:6:42", "typeDescriptions": { "typeIdentifier": "t_int216", "typeString": "int216" } }, "value": null, "visibility": "internal" } ], "src": "2138:14:42" }, "payable": false, "returnParameters": { "id": 14840, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 14839, "name": "", "nodeType": "VariableDeclaration", "scope": 14848, "src": "2176:6:42", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" }, "typeName": { "id": 14838, "name": "int256", "nodeType": "ElementaryTypeName", "src": "2176:6:42", "typeDescriptions": { "typeIdentifier": "t_int256", "typeString": "int256" } }, "value": null, "visibility": "internal" } ], "src": "2175:8:42" }, "scope": 15770,