Skip to content

Commit 11800c1

Browse files
thejesh23claude
andcommitted
maths/largest_of_very_large_numbers: validate positive input
The docstring already documents that res(-1, 5) should raise `ValueError: expected a positive input`, but no such validation exists. Calling res() with a negative x currently reaches `math.log10(x)` and raises `ValueError: math domain error` instead, so the documented doctest fails. Add the missing check at the top of the function so it matches the documented contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c0db072 commit 11800c1

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

maths/largest_of_very_large_numbers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def res(x, y):
1717
...
1818
ValueError: expected a positive input
1919
"""
20+
if x < 0:
21+
raise ValueError("expected a positive input")
2022
if 0 not in (x, y):
2123
# We use the relation x^y = y*log10(x), where 10 is the base.
2224
return y * math.log10(x)

0 commit comments

Comments
 (0)