3 ms·
"Number" and "i32" are entirely different types. What happens if you have an impedance mismatch?
by bpicolo 9y ago
"Number" and "i32" are entirely different types. What happens if you have an impedance mismatch?
- moron4hire 9y agoThe most popular JavaScript engines do indeed have real integers available. You can get real Integers in regular JavaScript, they are just cumbersome. But if you're transpiling, you can hide that difficulty away.
- Franciscouzo 9y agoIEEE 754 double precision floats have enough precision to represent every 32 bit integer, the problem is when you try to use them to represent 64 bit integers, you get problems such as this: https://github.com/nodejs/node/issues/12115 https://github.com/nodejs/node/issues/12115
- bpicolo 9y agoMy question is: what happens when you pass something that's not an integer to the rust lib code via this?
- hackcasual 9y agoJavaScript also has somewhat arcane rules around when Number it's actually treated like an i32
- ianjsikes 9y agoAuthor here. It is my cursory understanding that the Emscripten SDK handles converting types to and from Javascript values and C-like data in the module's virtual memory. I'm not totally sure how that conversion is happening yet. I can tell you that when I pass a string when it expects an i32, it treats it as 0, so `add("foo", "bar") -> 0`
- bpicolo 9y agoWonder if it will be possible to make it panic/error instead