PythonJS now has a new static type long that can be used to mark a variable as a 64bit integer, see this commit. JavaScript has no native support for native 64bit integers, so the translator will use the Long.js API to construct a Long object and call the appropriate methods for math and comparison logic.
python input
def main(): long x = 65536 long y = x * x long z = 4294967296 TestError( y==z ) long a = z + z long b = 8589934592 TestError( a==b ) TestError( y < b ) TestError( b > y ) TestError( y <= b ) TestError( b >= y )
javascript output
main = function() {
if (__NODEJS__==true) var long = require('long');
x = long.fromString("65536");
y = x.multiply(x);
z = long.fromString("4294967296");
TestError( y.equals(z) );
a = z.add(z);
b = long.fromString("8589934592");
TestError( a.equals(b) );
TestError( y.lessThan(b) );
TestError( b.greaterThan(y) );
TestError( y.lessThanOrEqual(b) );
TestError( b.greaterThanOrEqual(y) );
}
No comments:
Post a Comment