Browse Source

Merge pull request #3652 from georgkoester/issue/java_int64_negation_fix

Make Int64.neg use negation on java and not bitwise negation.
Cauê Waneck 10 years ago
parent
commit
14c9dfee81
3 changed files with 8 additions and 2 deletions
  1. 1 1
      std/cs/_std/haxe/Int64.hx
  2. 1 1
      std/java/_std/haxe/Int64.hx
  3. 6 0
      tests/unit/src/unit/TestInt64.hx

+ 1 - 1
std/cs/_std/haxe/Int64.hx

@@ -113,7 +113,7 @@ import cs.StdTypes.UInt64 in NativeUInt64;
 
 	public static inline function neg( a : Int64 ) : Int64
 	{
-		return (~(a.asNative())).ofNative();
+		return (-(a.asNative())).ofNative();
 	}
 
 	public static inline function isNeg( a : Int64 ) : Bool

+ 1 - 1
std/java/_std/haxe/Int64.hx

@@ -111,7 +111,7 @@ import java.StdTypes.Int64 in NativeInt64;
 
 	public static inline function neg( a : Int64 ) : Int64
 	{
-		return (~(a.asNative())).ofNative();
+		return (-(a.asNative())).ofNative();
 	}
 
 	public static inline function isNeg( a : Int64 ) : Bool

+ 6 - 0
tests/unit/src/unit/TestInt64.hx

@@ -106,4 +106,10 @@ class TestInt64 extends Test {
 		eq( a.add(make(0x1, 0)).toStr(), '4294967299');
 	}
 
+	public function testNeg()
+	{
+		eq(Std.string(ofInt(-1)),Std.string(neg(ofInt(1))));
+		eq(Std.string(ofInt(-100)),Std.string(neg(ofInt(100))));
+		eq(Std.string(make(-2147483648, 1)), Std.string(neg(make(2147483647, -1)))); // -9223372036854775807 == neg(9223372036854775807)
+	}
 }