Created
September 9, 2013 16:34
-
-
Save elliott5/6498174 to your computer and use it in GitHub Desktop.
working ucompare() for haxe.Int64 java and cs platforms (using my internal type defintions, sorry)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function ucompare(x:HaxeInt64abs,y:HaxeInt64abs):Int { | |
#if ( java || cs ) | |
// unsigned compare library code does not work properly for these platforms | |
if(HaxeInt64Typedef.isZero(x)) { | |
if(HaxeInt64Typedef.isZero(y)) { | |
return 0; | |
} else { | |
return -1; // any value is larger than x | |
} | |
} | |
if(HaxeInt64Typedef.isZero(y)) { // if we are here, we know that x is non-zero | |
return 1; // any value of x is larger than y | |
} | |
if(!HaxeInt64Typedef.isNeg(x)) { // x +ve | |
if(!HaxeInt64Typedef.isNeg(y)){ // both +ve so normal comparison | |
return HaxeInt64Typedef.compare(x,y); | |
}else{ // y -ve and so larger than x | |
return -1; | |
} | |
}else { // x -ve | |
if(!HaxeInt64Typedef.isNeg(y)){ // -ve x larger than +ve y | |
return 1; | |
}else{ // both are -ve so the normal comparison | |
return HaxeInt64Typedef.compare(x,y); //eg -1::-7 gives -1--7 = +6 meaning -1 > -7 which is correct for unsigned | |
} | |
} | |
#else | |
return HaxeInt64Typedef.ucompare(x,y); | |
#end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment