fix: correct misleading error message in MidpointIntegration by shaked-shlomo · Pull Request #1902 · TheAlgorithms/JavaScript · GitHub
Skip to content

fix: correct misleading error message in MidpointIntegration#1902

Open
shaked-shlomo wants to merge 1 commit into
TheAlgorithms:masterfrom
shaked-shlomo:fix/midpoint-integration-error-message
Open

fix: correct misleading error message in MidpointIntegration#1902
shaked-shlomo wants to merge 1 commit into
TheAlgorithms:masterfrom
shaked-shlomo:fix/midpoint-integration-error-message

Conversation

@shaked-shlomo

Copy link
Copy Markdown

Description

In Maths/MidpointIntegration.js the guard rejects non-positive N:

if (N <= 0) {
  throw Error('N has to be >= 2')
} // check if N > 0

The thrown message says 'N has to be >= 2', but:

  • the check only rejects N <= 0,
  • the inline comment says check if N > 0, and
  • the function docstring states "N must be > 0".

N = 1 is a valid number of subintervals for the midpoint rule, so the >= 2 message is incorrect and misleading. This changes it to 'N has to be > 0' to match the actual validation and the documentation.

(Note: the analogous >= 2 message in SimpsonIntegration.js is correct there, since Simpson's rule additionally requires an even N, so the minimum is 2 — left unchanged.)

Checklist

  • Fix is a single, self-contained change.
  • No existing test asserts the old message.
  • No behavior change beyond the error string.

🤖 Generated with Claude Code

The validation throws when N <= 0, and the docstring states 'N must be > 0',
but the message claimed 'N has to be >= 2'. N = 1 is valid for the midpoint
rule, so the message now matches the actual check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shaked-shlomo shaked-shlomo requested a review from appgurueu as a code owner June 1, 2026 13:30
@codecov-commenter

codecov-commenter commented Jun 1, 2026

Copy link
Copy Markdown

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.

2 participants