Int64 Bitwise operations issue


#1

Hi @ all, :wave:

I am a little bit stuck at the moment with the differences in Int64 bitwise operations between Reason and Kotlin.
I have the following code in my application:

let rotr = (x, n) => Int64.shift_right(x, n)->Int64.logor(Int64.shift_left(x, (63 - n)));

rotr(Int64.of_string("1056855588373528573"), 6)->Int64.to_string->Js.log
/* 
	Kotlin: -415832195659231233
    Reason: -415832195659231233
*/


rotr(Int64.of_string("-1056855588373528573"), 6)->Int64.to_string->Js.log
/* 
	Kotlin: 559947383735087104
    Reason: -16513368568336384
*/

As you can see, when working with positive Int64 numbers, everything works the same. As soon as the Int64 gets negative, both languages behave differently. I am currently porting a library from Kotlin to Reason, so Kotlins behaviour is the one i would expect to be the correct one.

Is this a bug or do I just don’t understand something?

Here are the two links to the playgrounds:
Kotlin
Reason

Thank you for your help!
:heart: Torben


#2

This was just an error I made.
It was Int64.shift_right_logical instead of Int64.shift_right :upside_down_face: