Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minifier produces incorrect constant value on large floating-point value #9256

Closed
levi-nz opened this issue Jul 15, 2024 · 4 comments · Fixed by #9258
Closed

minifier produces incorrect constant value on large floating-point value #9256

levi-nz opened this issue Jul 15, 2024 · 4 comments · Fixed by #9258
Labels
Milestone

Comments

@levi-nz
Copy link
Contributor

levi-nz commented Jul 15, 2024

Describe the bug

Running 1.7976931348623157e+308 << 1 in NodeJS v20.12.2 and in browser (Firefox) returns 0 but SWC minifier transforms this into -2.

For reference, 1.7976931348623157e+308 is Number.MAX_VALUE in JavaScript and f64::MAX in Rust.

Input code

1.7976931348623157e+308 << 1

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAA0vTMNQztzQ3szQ2NDaxMDMyNjQ1T9U2NrBQsLFRMNTkAgCxoDjzIAAAAA%3D%3D&config=H4sIAAAAAAAAA32UO3LjMAyG%2B5zCozrFjostcoDtcgYOTYIyvXxoCNCxJuO7L0TJj40hdRI%2B%2FAAJgPh%2B2%2B26E5ruY%2FfNn%2Fwz6IJQ7v9swTGRvrClAxM1muIH6t5v9IQTcjogNNN1Jh3p0gM1Fe5%2F7feLogs5I9wUiy365N34nNPkOBRAfLKxlUPWCInwf%2F3CSv6aAJX6bD%2FkHECnDaI0Kp8IeihSYJND0AOCOusiRJlOqovHLKWYYCWwaih5EHmynnxOnPOVWtBWmWxBQL6AIX8GSca5WJaQryfcp2ELh9r3rc8%2F1HDWoWoScsKltYRPK0Q9Zo%2BkXE1SCWe4UoMZLsX9qfROFaBa0qvulH1a6clfAK5A0IhJR5DiNg%2FH87SmdptKnxyPLI0C5%2FmWbpmg56Iq751Q2akyUMhL3Sxgq4GpskY6zoJXyofeggLneFaE0PjlyRylpDQOkJ0AuL%2FaSVM1A3V%2FhSt8ehAb%2BA%2FfkuQBWzyipuM6xTEecthIEIGO2W44cCsor%2BPCW%2BIyrPOaLPBogBVdKjbwugT4AVBWoe3Ll9ng58ERVR%2Fy4bEmFofrfQ9HnfrHe59X8dvi0MVsa4PLkp%2F6O6%2Fm393D6baF7wfvPH7elC3p9R%2BoYzQdMAYAAA%3D%3D

SWC Info output

No response

Expected behavior

Should be transformed to f(0)

Actual behavior

Transforms to f(-2)

Version

1.6.7

Additional context

No response

@levi-nz levi-nz added the C-bug label Jul 15, 2024
@kdy1 kdy1 added this to the Planned milestone Jul 15, 2024
@levi-nz
Copy link
Contributor Author

levi-nz commented Jul 15, 2024

I believe the problem is js_convert_double_to_bits not returning 0 if the value exceeds 32-bit integer limit as defined in ToInt32

@levi-nz
Copy link
Contributor Author

levi-nz commented Jul 16, 2024

Not sure if we need to use overflowing_* here for shifting

levi-nz added a commit to levi-nz/swc that referenced this issue Jul 16, 2024
@kdy1 kdy1 closed this as completed in baeb9e2 Jul 16, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.7.0 Jul 17, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 17, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants