Last active
August 29, 2015 14:09
-
-
Save jcward/39ba3311a7f7312be46a to your computer and use it in GitHub Desktop.
Testing Int, Std.random in Haxe 3.1.3, Neko 2.0
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
// Testing with Haxe 3.1.3 and Neko 2.0 | |
class Rand { | |
static function intArg(ii:Int) { | |
trace(" - got intArg: "+ii); | |
} | |
static function main() { | |
var i1:Int = 0xffffffff; | |
trace("0xFFFFFFF = "+i1); | |
var i2:Int = 0x7fffffff; | |
trace("0x7FFFFFF = "+i2); | |
var i3:Int = 0x80000000; | |
trace("0x8000000 = "+i3); | |
// Hex literals are Int unless explicitly cast | |
trace(0xffffffff); // Literals are Int, not UInt, so -1 | |
trace(0x80000000); // Literals are Int, not UInt, so -2147483648 | |
trace(cast(0xffffffff, UInt)); // Cast to UInt, result is 4294967295 | |
// Decimal literals work as UInt, but... | |
trace(4294967295); | |
// CPP: build fails!!! | |
// Neko: 4294967295 | |
// SWF: 4294967295 | |
// What about bigger than 32-bit? | |
trace(8294239847967295); | |
// CPP: build fails!!! | |
// Neko: 8.2942398479673e+15 | |
// SWF: 8294239847967295 | |
// Std.random takes Int, so the max random number is 31-bits... | |
trace("Random: "+Std.random(0x7FFFFFFF)); // but Neko 2.0 throws!!! | |
trace("Random: "+Std.random(0x3FFFFFFF)); // Neko 2.0 doesn't throw | |
// Neko 2.0 doesn't throw calling my own function with max int... | |
intArg(0x7FFFFFFF); | |
//Sys.exit(0x7FFFFFFF); // Neko 2.0 throws!!! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment