Skip to content

fix: handle division by zero in calculator#146

Open
quantcode-agent[bot] wants to merge 1 commit intomainfrom
quantcode/job-job-50f6f190
Open

fix: handle division by zero in calculator#146
quantcode-agent[bot] wants to merge 1 commit intomainfrom
quantcode/job-job-50f6f190

Conversation

@quantcode-agent
Copy link
Copy Markdown

Summary

  • Added a guard clause in src/calculator.ts divide() function to throw an Error("Division by zero") when the divisor is zero, instead of returning Infinity
  • Added tests in test/calculator.test.ts verifying both normal division and the division-by-zero error case

Assumptions

  • Throwing an Error is the appropriate behavior for division by zero (rather than returning null, NaN, or a result object)
  • The error message "Division by zero" is sufficient for consumers to identify the issue

All 5 tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants