-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
convertPathData introduces floating point precision errors at high precision settings (CLI) #2199
Description
Describe the bug
I encountered an issue where convertPathData produces significantly larger output because a number gets "rounded" to a much longer floating-point form (e.g., ending in ...9999996). This seems to be a floating-point precision bug that occurs specifically when using the CLI.
To Reproduce
Steps to reproduce the behavior:
- Create a file named test.svg with the following content:
<svg><path d="M13.017 2.13-4.61-1.265"/></svg>
- Create a config file named config.cjs:
module.exports = { plugins: ['convertPathData'], };
- Run the SVGO CLI command with precision set to
16:npx svgo test.svg --config config.cjs --input test.svg --output result.svg -p 16
- Observe the output in
result.svg.
Expected behavior
The output numbers should remain concise and correct, rather than expanding into long floating-point representations that actually increase the file size.
Actual Output
<svg><path d="m13.017 2.13-17.627-3.3949999999999996"/></svg>Desktop (please complete the following information):
- SVGO Version
4.0.0 - Node.js Version
20.19.1 - npm version
10.8.2 - OS:
Ubuntu 20.04.0 LTS
Additional context
-
I can only replicate this with the CLI tool. I could not replicate it when using SVGO as an NPM library.I was able to replicate using SVGO as an NPM library, see comment below -
In this minimal reproduction case above, setting
-p 15resolves the issuechanges the behavior to a more acceptable output, but is still longer than if it didn't change anything. See comment about it below.