From 11800c1703fd72e2f5829da1130756a9803837ea Mon Sep 17 00:00:00 2001 From: thejesh Date: Mon, 13 Jul 2026 20:05:03 -0700 Subject: [PATCH] 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) --- maths/largest_of_very_large_numbers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maths/largest_of_very_large_numbers.py b/maths/largest_of_very_large_numbers.py index e38ab2edb932..7dc48f5654e8 100644 --- a/maths/largest_of_very_large_numbers.py +++ b/maths/largest_of_very_large_numbers.py @@ -17,6 +17,8 @@ def res(x, y): ... ValueError: expected a positive input """ + if x < 0: + raise ValueError("expected a positive input") if 0 not in (x, y): # We use the relation x^y = y*log10(x), where 10 is the base. return y * math.log10(x)