-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
rolldown/rolldown
#8848Description
When importing a JSON file containing numbers with 17 significant digits (the maximum meaningful precision for IEEE 754 double-precision floats), Vite 8 truncates them to 16 significant digits in the bundle output. This silently changes the runtime value.
Inline number literals in JS/TS files are not affected - only numbers from JSON imports.
Reproduction
https://github.com/elderapo/vite-float-precision-bug
git clone https://github.com/elderapo/vite-float-precision-bug
cd vite-float-precision-bug
npm install
# Vite 8 - 4/8 values are corrupted
npx vite build && npx vite preview
# Vite 7 - all 8 values preserved correctly
npm install vite@7
npx vite build --outDir dist-v7 && npx vite preview --outDir dist-v7Example
src/data.json:
{ "values": [114.35143799257997, 406.31486713248995] }src/main.js:
import data from "./data.json";
console.log(data.values[0] === 114.35143799257997); // false in Vite 8, true in Vite 7
console.log(data.values[1] === 406.31486713248995); // false in Vite 8, true in Vite 7What happens in the bundle:
| Source JSON | Vite 7 (esbuild) | Vite 8 (rolldown) |
|---|---|---|
114.35143799257997 |
114.35143799257997 |
114.35143799257996 |
406.31486713248995 |
406.31486713248995 |
406.3148671324899 |
The last significant digit is dropped, which maps to a different IEEE 754 double.
Impact
Any application relying on exact float values from JSON will silently get wrong data. This affects physics simulations, deterministic algorithms, coordinate data, scientific datasets, etc.
Environment
- Vite 8.0.1
- Node.js v22
- Linux x86_64
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels