Skip to content

Fix unnecessary float to int cast for strtol #733

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

Merged
merged 2 commits into from
Jul 29, 2019
Merged

Fix unnecessary float to int cast for strtol #733

merged 2 commits into from
Jul 29, 2019

Conversation

MaxGraey
Copy link
Member

Fix #732

@MaxGraey MaxGraey requested a review from dcodeIO July 27, 2019 10:14
@MaxGraey MaxGraey changed the title Fix float to int cast for strtol Fix unnecessary float to int cast for strtol Jul 27, 2019
@MaxGraey
Copy link
Member Author

MaxGraey commented Jul 27, 2019

Previous behaviour cause to "invalid integer conversion" trap

  f64.const nan:0x8000000000000
  i32.trunc_f64_s

So may be better throw exception instead return zero for non-float values. Or throw exception for any type and don't use NaN for floats.
@dcodeIO wdyt?

@dcodeIO
Copy link
Member

dcodeIO commented Jul 27, 2019

Looks good. I believe the sole reason for the NaNs there was compatibility of return values when used inside parseInt, which operates on f64 and returns NaN on invalid inputs etc. Previous behavior for i32 was intended to return 0 (after casting), and since that remains the same (but removes the casting, I think the trap is unintentional), the fix should be just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AS that does not use floats should not compile into Wasm that uses floats
2 participants