@tecfu/is-multiple-of
v2.0.0
Published
Floating point modulus for javascript.
Readme
is-multiple-of
Floating point modulus operator functionality for javascript.
The implementation normalizes decimal values into integers and uses BigInt arithmetic, avoiding the rounding errors of JavaScript's % operator for decimal inputs. Numeric strings and scientific notation are supported without the old six-decimal-place limitation.
Rationale
JavaScript can't always divide floats accurately: for example:
4.55 % 0.05 === 0 // falsewhereas:
multipleOf(4.55, 0.05) // trueInstallation
$ npm install @tecfu/is-multiple-ofUsage
import multipleOf from '@tecfu/is-multiple-of'
multipleOf(4.55, 0.05) // true
multipleOf('7e-20', '1e-20') // true
multipleOf('9007199254740993', '3') // trueInputs must be finite numbers or decimal numeric strings. Values such as booleans, empty strings, NaN, and Infinity are rejected.
Version Compatibility
| Node Version | multipleOf Version | | ------------ | ------------------ | | 18+ | >= 1.0 |
Running tests
$ npm testPull Requests
Pull requests are encouraged!
- Please remember to add a unit test when necessary
- Please format your commit messages according to the "Conventional Commits" specification
If you aren't familiar with Conventional Commits, here's a good article on the topic
TL/DR:
- feat: a feature that is visible for end users.
- fix: a bugfix that is visible for end users.
- chore: a change that doesn't impact end users (e.g. changes to CI pipeline)
- docs: a change in the README or documentation
- refactor: a change in production code focused on readability, style and/or performance.
License
Copyright 2020, Tecfu.
