-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
invalid type: floating point after math operations #1962
Comments
I sort of mentioned this before in #1147 |
Just to explain this. The reason is that there is no such thing as an "integer" type in JavaScript. All numeric types are 64-bit floating point numbers. So this should never work like this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type |
Yes thank you. This goes back to my latest comment here: #1961 (comment) I would just like some kind of let my_u32: u32 = my_js_value.into(); If we could have something like that for arbitrary structs, enums, etc that would be excellent. Does this functionality exist? |
This Pull Request fixes/closes #1962. It changes the following: - When executing arithmetic operations on `JsValue`s, try to use integer operations and fallback to `f64` operations on error. - Adds tests for serde_json conversions from integer operations.
Describe the bug
I have been using the new JsValue
to_json
functionality and I'm running into some issues. I am dealing with numbers in JS that should be valid integers, whether they be u32, i32, etc. boa seems to have issues withto_json
because it is converting them intoRational
s for an unknown reason. This might be related to #1961.To Reproduce
Expected behavior
This should print
get_u32: 999500
and should not error out. Instead I get this error:Build environment (please complete the following information):
Additional context
It seems like certain math operations are causing a Rust representation of
Rational
unnecessarily.The text was updated successfully, but these errors were encountered: