Skip to content

Instantly share code, notes, and snippets.

@gerdr
Last active December 19, 2015 07:58
Show Gist options
  • Save gerdr/5922055 to your computer and use it in GitHub Desktop.
Save gerdr/5922055 to your computer and use it in GitHub Desktop.
shift semantics
Rakudo/Parrot, int and (soon) Int:
17 +> 3 = 2 # 17 div 2**3
-17 +> 3 = -3 # floor(-17 / 2**3)
17 +> -3 = 136 # 17 <+ 3 = 17 * 2**3
-17 +> -3 = -136 # -17 <+ 3 = -17 * 2**3
17 +< 3 = 136 # 17 * 2**3
-17 +< 3 = -136 # -17 * 2**3
17 +< -3 = 2 # 17 +> 3 = 17 div 2**3
-17 +< -3 = -3 # -17 +> 3 = floor(-17 / 2**3)
Niecza (via C#), Java:
17 +> 3 = 2 # 17 div 2**3
-17 +> 3 = -3 # floor(-17 / 2**3)
17 +> -3 = 0 # 17 +> (32 - 3) = 17 div 2**(32 - 3)
-17 +> -3 = -1 # -17 +> (32 - 3) = floor(-17 / 2**(32 - 3))
17 +< 3 = 136 # 17 * 2**3
-17 +< 3 = -136 # -17 * 2**3
17 +< -3 = 536870912 # 17 +< (32 - 3) = (17 * 2**(32 - 3)) mod 2**32
-17 +< -3 = -536870912 # -17 +< (32 - 3) = (-17 * 2**(32 - 3)) mod 2**32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment