| 39 | |
| 40 | // immutable 64-bit integer |
| 41 | export 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( |
| 81 | low >>> 0, |
| 82 | ((~u32[1] >>> 0) + (low > 0xffffffff)) >>> 0, |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | eq(b) { |
| 87 | const values = lohi_from_one(b); |
| 88 | const u32 = this._u32; |
| 89 | return ( |
| 90 | u32[0] === values[0] |
| 91 | && u32[1] === values[1] |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | ne(b) { |
| 96 | return !this.eq(b); |
| 97 | } |
| 98 |
nothing calls this directly
no outgoing calls
no test coverage detected