Browse Source

treat UInt >>> like >> (closes #2736)

Simon Krajewski 10 years ago
parent
commit
40ad5904fb
2 changed files with 5 additions and 12 deletions
  1. 2 2
      std/UInt.hx
  2. 3 10
      tests/unit/src/unit/issues/Issue2736.hx

+ 2 - 2
std/UInt.hx

@@ -61,7 +61,7 @@ abstract UInt to Int from Int
 	@:op(A&B) private static function and(lhs:UInt, rhs:UInt):UInt;
 	@:op(A&B) private static function and(lhs:UInt, rhs:UInt):UInt;
 
 
 	@:op(A<<B) private static function shl(lhs:UInt, rhs:Int):UInt;
 	@:op(A<<B) private static function shl(lhs:UInt, rhs:Int):UInt;
-	@:op(A>>B) private static function shr(lhs:UInt, rhs:Int):UInt;
+	@:op(A>>B) private static inline function shr(lhs:UInt, rhs:Int):UInt return lhs >>> rhs;
 	@:op(A>>>B) private static function ushr(lhs:UInt, rhs:Int):UInt;
 	@:op(A>>>B) private static function ushr(lhs:UInt, rhs:Int):UInt;
 
 
 	@:op(A>B) private static function gt(lhs:UInt, rhs:UInt):Bool;
 	@:op(A>B) private static function gt(lhs:UInt, rhs:UInt):Bool;
@@ -154,7 +154,7 @@ abstract UInt(Int) from Int to Int {
 	}
 	}
 
 
 	@:op(A >> B) private static inline function shr(a:UInt, b:Int):UInt {
 	@:op(A >> B) private static inline function shr(a:UInt, b:Int):UInt {
-		return a.toInt() >> b;
+		return a.toInt() >>> b;
 	}
 	}
 
 
 	@:op(A >>> B) private static inline function ushr(a:UInt, b:Int):UInt {
 	@:op(A >>> B) private static inline function ushr(a:UInt, b:Int):UInt {

+ 3 - 10
tests/unit/src/unit/issues/Issue2736.hx

@@ -22,15 +22,8 @@ class Issue2736 extends Test {
         t( a > 1.0 ); t( a >= 1.0 );
         t( a > 1.0 ); t( a >= 1.0 );
         f( a < -1.0 ); f( a <= 1.0 );
         f( a < -1.0 ); f( a <= 1.0 );
 
 
-        // Shift behavior
-        //eq( '${a >> 1}', "3397483648" ); // broken
-
-        /* These are currently broken but should be fixed in the future:
-		 * Currently we don't allow UInt vs Int comparisons.
-         * trace(a == -1794967296);
-
-         * Shift on swf9 return as Int and not UInt
-         * trace(a >> 1); //-897483648 in flash, but 3397483648 in neko and js
-         */
+		var u:UInt = 2147483648;
+        eq(1073741824, u >> 1);
+        eq(1073741824, u >>> 1);
 	}
 	}
 }
 }