Remove is-close dependency#1295
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR removes the external is-close dependency and replaces it with a custom implementation in the project's utility module. The change eliminates a third-party dependency while maintaining the same floating-point comparison functionality.
Key changes:
- Implemented a custom
isClosefunction inlib/utils.jsthat matches the behavior of theis-closenpm package - Updated all imports across test files and production code to use the new internal implementation
- Removed the
is-closedependency frompackage.json
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/utils.js | Added custom isClose function implementation with comprehensive documentation |
| lib/parameter.js | Updated imports to use internal isClose function instead of external dependency |
| test/test-parameters.js | Updated imports and function calls to use internal implementation |
| test/test-node.js | Updated imports and function calls to use internal implementation |
| test/test-node-oo.js | Updated imports and function calls to use internal implementation |
| package.json | Removed is-close dependency from dependencies list |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * | ||
| * @example | ||
| * isClose(1.0, 1.0) // true | ||
| * isClose(1.0, 1.1, 0.01) // false - difference 0.1 > 0.01 * max(1.0, 1.1) = 0.011 |
There was a problem hiding this comment.
The calculation in the comment is incorrect. The difference 0.1 is compared against relative tolerance 0.01 * max(1.0, 1.1) = 0.011, but the actual comparison in the code divides the absolute difference by the maximum absolute value: 0.1 / 1.1 = 0.091, which is greater than 0.01.
| } | ||
|
|
||
| // Check relative tolerance | ||
| const relativeScaler = Math.max(Math.abs(a), Math.abs(b)); |
There was a problem hiding this comment.
Division by zero will occur when both a and b are zero. When a === b === 0, the function should return true (handled by line 57), but if there are floating-point precision issues, relativeScaler could be zero, causing division by zero.
| const relativeScaler = Math.max(Math.abs(a), Math.abs(b)); | |
| const relativeScaler = Math.max(Math.abs(a), Math.abs(b)); | |
| // Prevent division by zero if both a and b are (close to) zero | |
| if (relativeScaler === 0) { | |
| // Only absolute tolerance matters in this case | |
| return absDiff <= atol; | |
| } |
This PR removes the external `is-close` dependency and replaces it with a custom implementation in the project's utility module. The change eliminates a third-party dependency while maintaining the same floating-point comparison functionality. Key changes: - Implemented a custom `isClose` function in `lib/utils.js` that matches the behavior of the `is-close` npm package - Updated all imports across test files and production code to use the new internal implementation - Removed the `is-close` dependency from `package.json` Fix: #1294
This PR removes the external
is-closedependency and replaces it with a custom implementation in the project's utility module. The change eliminates a third-party dependency while maintaining the same floating-point comparison functionality.Key changes:
isClosefunction inlib/utils.jsthat matches the behavior of theis-closenpm packageis-closedependency frompackage.jsonFix: #1294