koma icon indicating copy to clipboard operation
koma copied to clipboard

Weird bug with augmented assignment and Int constant value

Open tobia opened this issue 4 years ago • 2 comments

I spent hours tracking down this bug, because the code compiled and looked fine to me:

val m1 = mat[0.5]
m1[0] -= 1
println(m1[0]) // 0.0 WRONG!

When I replaced the 1 with 1.0 (out of lack of things to try) the bug went away:

val m2 = mat[0.5]
m2[0] -= 1.0
println(m2[0]) // -0.5 correct

What's weird is that Kotlin has no issue with auto-casting a constant to double:

val m3 = mat[0.5]
println(m3[0] - 1) // -0.5 correct

So the bug only appears when using augmented assignments (+=, -=, etc.)

I have no idea how to debug this.

I'm using Koma EJML 0.12, Kotlin 1.3.61, Java 1.8.0_242

tobia avatar Mar 07 '20 20:03 tobia

Thanks for the report.

This project is only lightly maintained at the moment, but we'll try to take a look when possible.

kyonifer avatar Mar 12 '20 16:03 kyonifer

Sure. I just wanted to open an issue in case others run into it. In fact, augmented assignments are converted to regular assignments by the Kotlin compiler, so I don't exclude the possibility that this is a Kotlin compiler bug.

In any case, it may be lightly maintained as of now, but it's still the best math library for Kotlin bar none.

tobia avatar Mar 12 '20 18:03 tobia