forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegerUtilities.ts
More file actions
28 lines (22 loc) · 913 Bytes
/
integerUtilities.ts
File metadata and controls
28 lines (22 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
///<reference path='references.ts' />
module TypeScript {
export module IntegerUtilities {
export function integerDivide(numerator: number, denominator: number): number {
return (numerator / denominator) >> 0;
}
export function integerMultiplyLow32Bits(n1: number, n2: number): number {
var n1Low16 = n1 & 0x0000ffff;
var n1High16 = n1 >>> 16;
var n2Low16 = n2 & 0x0000ffff;
var n2High16 = n2 >>> 16;
var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0;
return resultLow32;
}
export function isInteger(text: string): boolean {
return /^[0-9]+$/.test(text);
}
export function isHexInteger(text: string): boolean {
return /^0(x|X)[0-9a-fA-F]+$/.test(text);
}
}
}