{"record":{"id":"e6eaa697fde576b5","repo":"TheAlgorithms/Python","slug":"input-value-must-be-a-int-type-e6eaa6","errorCode":null,"errorMessage":"Input value must be a 'int' type","messagePattern":"Input value must be a 'int' type","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/largest_pow_of_two_le_num.py","lineNumber":48,"sourceCode":"    >>> largest_pow_of_two_le_num(-1)\n    0\n    >>> largest_pow_of_two_le_num(3)\n    2\n    >>> largest_pow_of_two_le_num(15)\n    8\n    >>> largest_pow_of_two_le_num(99)\n    64\n    >>> largest_pow_of_two_le_num(178)\n    128\n    >>> largest_pow_of_two_le_num(999999)\n    524288\n    >>> largest_pow_of_two_le_num(99.9)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value must be a 'int' type\n    \"\"\"\n    if isinstance(number, float):\n        raise TypeError(\"Input value must be a 'int' type\")\n    if number <= 0:\n        return 0\n    res = 1\n    while (res << 1) <= number:\n        res <<= 1\n    return res\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":30,"sourceCodeEnd":61,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/largest_pow_of_two_le_num.py#L30-L61","documentation":"Raised by largest_pow_of_two_le_num when the argument is a float. The function doubles a result bit until it exceeds the number, requiring an integer; floats are explicitly rejected. Non-float non-ints (e.g., strings) are not guarded and fail with a comparison TypeError at `number <= 0`. Non-positive numbers return 0 instead of raising.","triggerScenarios":"Calling largest_pow_of_two_le_num(99.9) or any float. largest_pow_of_two_le_num(-5) does not raise — it returns 0.","commonSituations":"Sizing hash-table buckets or buffer blocks from computed loads that are floats; passing ratios or normalized values where an integer quantity was intended.","solutions":["Floor the input: largest_pow_of_two_le_num(int(x)) or math.floor(x) for floats.","Use bit_length for a closed form on positive ints: 1 << (n.bit_length() - 1) when n >= 1.","Validate capacity/size inputs as positive ints at config-load time."],"exampleFix":"# before\nlargest_pow_of_two_le_num(99.9)  # TypeError\n\n# after\nlargest_pow_of_two_le_num(int(99.9))  # 64","handlingStrategy":"type-guard","validationCode":"import math\nnumber = int(math.floor(number)) if isinstance(number, float) else number","typeGuard":"def is_int(value: object) -> bool:\n    return isinstance(value, int)","tryCatchPattern":null,"preventionTips":["Floor float capacities before power-of-two rounding.","Use 1 << (n.bit_length() - 1) for n >= 1 as a closed form.","Note non-positive inputs return 0 by design — handle that case if 0 is invalid for you."],"tags":["bit-manipulation","type-validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}