{
    "Function": "slitherConstructorConstantVariables",
    "File": "src/libraries/Math128x128.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "library Math128x128 {\n    using Math512Bits for uint256;\n    using BitMath for uint256;\n\n    uint256 constant LOG_SCALE_OFFSET = 127;\n    uint256 constant LOG_SCALE = 1 << LOG_SCALE_OFFSET;\n    uint256 constant LOG_SCALE_SQUARED = LOG_SCALE * LOG_SCALE;\n\n    /// @notice Calculates the binary logarithm of x.\n    ///\n    /// @dev Based on the iterative approximation algorithm.\n    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation\n    ///\n    /// Requirements:\n    /// - x must be greater than zero.\n    ///\n    /// Caveats:\n    /// - The results are not perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation\n    /// Also because x is converted to an unsigned 129.127-binary fixed-point number during the operation to optimize the multiplication\n    ///\n    /// @param x The unsigned 128.128-binary fixed-point number for which to calculate the binary logarithm.\n    /// @return result The binary logarithm as a signed 128.128-binary fixed-point number.\n    function log2(uint256 x) internal pure returns (int256 result) {\n        // Convert x to a unsigned 129.127-binary fixed-point number to optimize the multiplication.\n        // If we use an offset of 128 bits, y would need 129 bits and y**2 would would overflow and we would have to\n        // use mulDiv, by reducing x to 129.127-binary fixed-point number we assert that y will use 128 bits, and we\n        // can use the regular multiplication\n\n        if (x == 1) return 0;\n        if (x == 0) revert Math128x128__LogUnderflow();\n\n        x >>= 1;\n\n        unchecked {\n            // This works because log2(x) = -log2(1/x).\n            int256 sign;\n            if (x >= LOG_SCALE) {\n                sign = 1;\n            } else {\n                sign = -1;\n                // Do the fixed-point inversion inline to save gas\n                x = LOG_SCALE_SQUARED / x;\n            }\n\n            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).\n            uint256 n = (x >> LOG_SCALE_OFFSET).mostSignificantBit();\n\n            // The integer part of the logarithm as a signed 129.127-binary fixed-point number. The operation can't overflow\n            // because n is maximum 255, LOG_SCALE_OFFSET is 127 bits and sign is either 1 or -1.\n            result = int256(n) << LOG_SCALE_OFFSET;\n\n            // This is y = x * 2^(-n).\n            uint256 y = x >> n;\n\n            // If y = 1, the fractional part is zero.\n            if (y != LOG_SCALE) {\n                // Calculate the fractional part via the iterative approximation.\n                // The \"delta >>= 1\" part is equivalent to \"delta /= 2\", but shifting bits is faster.\n                for (int256 delta = int256(1 << (LOG_SCALE_OFFSET - 1)); delta > 0; delta >>= 1) {\n                    y = (y * y) >> LOG_SCALE_OFFSET;\n\n                    // Is y^2 > 2 and so in the range [2,4)?\n                    if (y >= 1 << (LOG_SCALE_OFFSET + 1)) {\n                        // Add the 2^(-m) factor to the logarithm.\n                        result += delta;\n\n                        // Corresponds to z/2 on Wikipedia.\n                        y >>= 1;\n                    }\n                }\n            }\n            // Convert x back to unsigned 128.128-binary fixed-point number\n            result = (result * sign) << 1;\n        }\n    }\n\n    /// @notice Returns the value of x^y. It calculates `1 / x^abs(y)` if x is bigger than 2^128.\n    /// At the end of the operations, we invert the result if needed.\n    /// @param x The unsigned 128.128-binary fixed-point number for which to calculate the power\n    /// @param y A relative number without any decimals, needs to be between ]2^20; 2^20[\n    /// @return result The result of `x^y`\n    function power(uint256 x, int256 y) internal pure returns (uint256 result) {\n        bool invert;\n        uint256 absY;\n\n        if (y == 0) return Constants.SCALE;\n\n        assembly {\n            absY := y\n            if slt(absY, 0) {\n                absY := sub(0, absY)\n                invert := iszero(invert)\n            }\n        }\n\n        if (absY < 0x100000) {\n            result = Constants.SCALE;\n            assembly {\n                let pow := x\n                if gt(x, 0xffffffffffffffffffffffffffffffff) {\n                    pow := div(not(0), pow)\n                    invert := iszero(invert)\n                }\n\n                if and(absY, 0x1) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x2) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x4) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x8) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x10) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x20) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x40) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x80) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x100) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x200) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x400) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x800) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x1000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x2000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x4000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x8000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x10000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x20000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x40000) {\n                    result := shr(128, mul(result, pow))\n                }\n                pow := shr(128, mul(pow, pow))\n                if and(absY, 0x80000) {\n                    result := shr(128, mul(result, pow))\n                }\n            }\n        }\n\n        // revert if y is too big or if x^y underflowed\n        if (result == 0) revert Math128x128__PowerUnderflow(x, y);\n\n        return invert ? type(uint256).max / result : result;\n    }\n}"
}