I'm adding wasmjs target support for my applicatio...
# webassembly
l
I'm adding wasmjs target support for my application, and I have found an inconsistency between wasmjs and all other platforms (I've tested on JVM, Linux and JS). The following code returns -0.0 for all these platforms, but 0.0 on wasmjs. Is this a bug?
Copy code
fun opDouble(x: Double, y: Double) =
     if (x == 0.0) y else (y % x).let { result -> if (result != 0.0 && ((x < 0 && y > 0) || (x > 0 && y < 0))) x + result else result }
 opDouble(2.0, -2.0)
r
The
%
operator returns different values on different targets. https://pl.kotl.in/V9JlKwE5c
I'm not sure what the Kotlin specification says about this kind of operation.
l
Your example is interesting, and also raises more questions. The JS target result doesn't match my observations.
In any case, I want to call this a bug, since the arithmetic operations are supposed to behave the same, no?
r
It's probably hard question. Users of Kotlin on JVM would probably want to have the results like Java, but users of Kotlin/JS would like to have the results match those of JS 🙂
l
That's fair, but at least JS and wasm should be the same, no?
r
No idea 🙂 Probably.
s
e
arithmetic operations are supposed to behave the same, no?
why? https://en.m.wikipedia.org/wiki/IEEE_754#Reproducibility does not guarantee that
l
@Svyatoslav Kuzmich [JB] Thanks a lot.