Hi everyone, I get different results using `cos` f...
# kotlin-native
o
Hi everyone, I get different results using
cos
function in K/N, i.e:
Copy code
@Test
fun cosine_functions_works_the_same_in_all_platform() {
    assertEquals(0.6441559905471732, cos(0.8708769899641021))
}
This test pass in JVM and JS, but fails in iOS:
kotlin.AssertionError: Expected <0.6441559905471732>, actual <0.6441559905471733>.
k
that's simply the nature of passing floating point numbers across language boundaries
there's a fuzzy version of assert equals
use a tolerance of something like .000001, or whatever works for you.
n
I can't seem to find a fuzzy version of
assertEquals
.
o
Yes, that's what I'm doing now, but I was actually worried about the implications, since it looks like a
Double
precision issue that might be related to the implementation of the functions in K/N
For instance, this is passing in all platforms:
Copy code
fun multiply(a: Double, b: Double) = a*b

@Test
fun cosine_functions_works_the_same_in_all_platform() {
    assertEquals(0.49271114849400754, 0.7648941494365021*0.6441559905471732)
    assertEquals(0.49271114849400754, multiply(0.7648941494365021, 0.6441559905471732))
}
Does the second case counts as
passing floating point numbers across language boundaries
? If so I'd expect a loss in the precision as happened with
cos
and
sin
functions
k
no, it doesn't go through a language binding
o
Ahh, I see
Just to see if I get it right, If I implement
multiply
function in C or ObjC and create the bindings, can I expect the loss in the precision too?
k
most likely
o
Nice, thanks for everything
🍻 2