Added definition for Long.js

This commit is contained in:
kerug
2014-05-18 17:49:46 +09:00
parent bb59fade92
commit 3cc801ffc3
2 changed files with 148 additions and 0 deletions

68
long/long-tests.ts Normal file
View File

@@ -0,0 +1,68 @@
/// <reference path="long.d.ts" />
// --- commonjs ---
import Long = require("long");
// --- browser ---
//var Long = dcodeIO.Long;
var val:Long;
var n:number;
var b:boolean;
var s:string;
val = new (<any>Long)(0xFFFFFFFF, 0x7FFFFFFF);
val = Long.from28Bits(0xFFFFFFF, 0xFFFFFFF, 0xFF);
val = Long.fromInt(-1, true);
n = val.low;
n = val.high;
b = val.unsigned;
s = val.toString();
val = val.add(val);
val = val.and(val);
val = val.clone();
n = val.compare(val);
val = val.div(val);
b = val.equals(val);
n = val.getHighBits();
n = val.getHighBitsUnsigned();
n = val.getLowBits();
n = val.getLowBitsUnsigned();
n = val.getNumBitsAbs();
b = val.greaterThan(val);
b = val.greaterThanOrEqual(val);
b = val.isEven();
b = val.isNegative();
b = val.isOdd();
b = val.isZero();
b = val.lessThan(val);
b = val.lessThanOrEqual(val);
val = val.modulo(val);
val = val.multiply(val);
val = val.negate();
val = val.not();
b = val.notEquals(val);
val = val.or(val);
val = val.shiftLeft(2);
val = val.shiftRight(1);
val = val.shiftRightUnsigned(1);
val = val.subtract(val);
n = val.toInt();
n = val.toNumber();
val = val.toSigned();
val = val.toUnsigned();
val = val.xor(val);
val = Long.MAX_SIGNED_VALUE;
val = Long.MAX_UNSIGNED_VALUE;
val = Long.MAX_VALUE;
val = Long.MIN_SIGNED_VALUE;
val = Long.MIN_UNSIGNED_VALUE;
val = Long.MIN_VALUE;
val = Long.NEG_ONE;
val = Long.ONE;
val = Long.ZERO;

80
long/long.d.ts vendored Normal file
View File

@@ -0,0 +1,80 @@
// Type definitions for Long.js 1.1.2
// Project: https://github.com/dcodeIO/Long.js
// Definitions by: Toshihide Hara <https://github.com/kerug/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface LongStatic {
MAX_SIGNED_VALUE:Long;
MAX_UNSIGNED_VALUE:Long;
MAX_VALUE:Long;
MIN_SIGNED_VALUE:Long;
MIN_UNSIGNED_VALUE:Long;
MIN_VALUE:Long;
NEG_ONE:Long;
ONE:Long;
ZERO:Long;
from28Bits(part0:number, part1:number, part2:number, unsigned?:boolean):Long;
fromBits(lowBits:number, highBits:number, unsigned?:boolean):Long;
fromInt(value:number, unsigned?:boolean):Long;
fromNumber(value:number, unsigned?:boolean):Long;
fromString(str:string, unsigned?:boolean, radix?:number):Long;
fromString(str:string, unsigned?:number, radix?:number):Long;
fromString(str:string, unsigned?:any, radix?:number):Long;
}
interface Long {
new(low:number, high:number, unsigned?:boolean):Long;
high:number;
low:number;
unsigned:boolean;
add(other:Long):Long;
and(other:Long):Long;
clone():Long;
compare(other:Long):number;
div(other:Long):Long;
equals(other:Long):boolean;
getHighBits():number;
getHighBitsUnsigned():number;
getLowBits():number;
getLowBitsUnsigned():number;
getNumBitsAbs():number;
greaterThan(other:Long):boolean;
greaterThanOrEqual(other:Long):boolean;
isEven():boolean;
isNegative():boolean;
isOdd():boolean;
isZero():boolean;
lessThan(other:Long):boolean;
lessThanOrEqual(other:Long):boolean;
modulo(other:Long):Long;
multiply(other:Long):Long;
negate():Long;
not():Long;
notEquals(other:Long):boolean;
or(other:Long):Long;
shiftLeft(numBits:number):Long;
shiftRight(numBits:number):Long;
shiftRightUnsigned(numBits:number):Long;
subtract(other:Long):Long;
toInt():number;
toNumber():number;
toSigned():Long;
toString(radix?:number):string;
toUnsigned():Long;
xor(other:Long):Long;
}
// for browser
declare module dcodeIO {
export var Long:LongStatic;
}
// for node, commonjs
declare var Long:LongStatic;
declare module "long" {
export = Long;
}