Open the context
Choose the project folder and name the files or behavior involved.
Sum at most 1000 finite numbers of magnitude at most 1e100 with a compensation term. Check cancellation around a small addend and empty input, rejecting Boolean and non-finite values before summation.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def compensated_sum(values):
values = tuple(values)
if len(values) > 1000 or any(type(v) not in (int, float) or
not -1e100 <= v <= 1e100 for v in values):
raise ValueError("values.range")
total = correction = 0.0
for value in values:
value = float(value)
next_total = total + value
correction += ((total - next_total) + value if abs(total) >= abs(value)
else (value - next_total) + total)
total = next_total
return total + correctionThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.