```\nfunction average(int256 a, int256 b) internal pure returns (int256) {\n    // Formula from the book "Hacker's Delight"\n    int256 x = (a & b) + ((a ^ b) >> 1);\n    return x + (int256(uint256(x) >> 255) & (a ^ b));\n}\n```\n