Skip to content

fix(isDivisibleBy): preserve integer divisors in exponent notation - #2939

Open
LucasLeao18 wants to merge 1 commit into
validatorjs:masterfrom
LucasLeao18:fix/divisibility-integer-divisor
Open

LucasLeao18 wants to merge 1 commit into
validatorjs:masterfrom
LucasLeao18:fix/divisibility-integer-divisor

Conversation

@LucasLeao18

Copy link
Copy Markdown

isDivisibleBy('1', 1e21) currently returns true: parseInt converts the numeric divisor to "1e+21" and truncates it to 1. Convert the divisor with Number and require an integer before applying the remainder operation. Large integer divisors then retain their value, while fractional, zero and non-finite divisors return false.

This follows the preference for integer divisors discussed in #1349 and #1350; it does not introduce approximate decimal divisibility. The README now states the divisor contract.

Validation on Node 24.15.0 / Windows:

  • The exponent-notation regression fails on the base implementation.
  • npm test: 325 passed, including build and lint; 100% line coverage.
  • Tests cover exponent notation, zero, fractional, negative fractional and non-finite divisors across the Node and browser forms exercised by the existing harness.

Checklist

  • PR contains only related changes.
  • README updated.
  • Regression tests included.
  • Related prior discussion linked above.

Prepared with OpenAI Codex; tests were run locally.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (2cb29c6).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2939   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2600    +1     
  Branches       658       659    +1     
=========================================
+ Hits          2599      2600    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant