MCPcopy Create free account
hub / github.com/GamerHack/GamerHack.github.io / Int

Class Int

g2all/700/module/int64.js:41–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40// immutable 64-bit integer
41export class Int {
42 constructor(low, high) {
43 if (high === undefined) {
44 this._u32 = new Uint32Array(lohi_from_one(low));
45 return;
46 }
47
48 if (check_not_in_range(low)) {
49 throw TypeError(`low not a 32-bit integer: ${low}`);
50 }
51
52 if (check_not_in_range(high)) {
53 throw TypeError(`high not a 32-bit integer: ${high}`);
54 }
55
56 this._u32 = new Uint32Array([low, high]);
57 }
58
59 get lo() {
60 return this._u32[0];
61 }
62
63 get hi() {
64 return this._u32[1];
65 }
66
67 // return low/high as signed integers
68
69 get bot() {
70 return this._u32[0] | 0;
71 }
72
73 get top() {
74 return this._u32[1] | 0;
75 }
76
77 neg() {
78 const u32 = this._u32;
79 const low = (~u32[0] >>> 0) + 1;
80 return new this.constructor(low >>> 0, ((~u32[1] >>> 0) + (low > 0xffffffff)) >>> 0);
81 }
82
83 eq(b) {
84 const values = lohi_from_one(b);
85 const u32 = this._u32;
86 return u32[0] === values[0] && u32[1] === values[1];
87 }
88
89 ne(b) {
90 return !this.eq(b);
91 }
92
93 add(b) {
94 const values = lohi_from_one(b);
95 const u32 = this._u32;
96 const low = u32[0] + values[0];
97 return new this.constructor(low >>> 0, (u32[1] + values[1] + (low > 0xffffffff)) >>> 0);
98 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected