◐ Shell
clean mode source ↗

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

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