| 123 | return number + ""; // always return a string |
| 124 | } |
| 125 | function Int64(low, high) { |
| 126 | var bytes = new Uint8Array(8); |
| 127 | |
| 128 | if (arguments.length > 2 || arguments.length == 0) |
| 129 | throw TypeError("Incorrect number of arguments to constructor"); |
| 130 | if (arguments.length == 2) { |
| 131 | if (typeof low != 'number' || typeof high != 'number') { |
| 132 | throw TypeError("Both arguments must be numbers"); |
| 133 | } |
| 134 | if (low > 0xffffffff || high > 0xffffffff || low < 0 || high < 0) { |
| 135 | throw RangeError("Both arguments must fit inside a uint32"); |
| 136 | } |
| 137 | low = low.toString(16); |
| 138 | for (let i = 0; i < 8 - low.length; i++) { |
| 139 | low = "0" + low; |
| 140 | } |
| 141 | low = "0x" + high.toString(16) + low; |
| 142 | } |
| 143 | |
| 144 | switch (typeof low) { |
| 145 | case 'number': |
| 146 | low = '0x' + Math.floor(low).toString(16); |
| 147 | case 'string': |
| 148 | if (low.substr(0, 2) === "0x") |
| 149 | low = low.substr(2); |
| 150 | if (low.length % 2 == 1) |
| 151 | low = '0' + low; |
| 152 | var bigEndian = unhexlify(low, 8); |
| 153 | var arr = []; |
| 154 | for (var i = 0; i < bigEndian.length; i++) { |
| 155 | arr[i] = bigEndian[i]; |
| 156 | } |
| 157 | bytes.set(arr.reverse()); |
| 158 | break; |
| 159 | case 'object': |
| 160 | if (low instanceof Int64) { |
| 161 | bytes.set(low.bytes()); |
| 162 | } else { |
| 163 | if (low.length != 8) |
| 164 | throw TypeError("Array must have excactly 8 elements."); |
| 165 | bytes.set(low); |
| 166 | } |
| 167 | break; |
| 168 | case 'undefined': |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | // Return a double whith the same underlying bit representation. |
| 173 | this.asDouble = function () { |
| 174 | // Check for NaN |
| 175 | if (bytes[7] == 0xff && (bytes[6] == 0xff || bytes[6] == 0xfe)) |
| 176 | throw new RangeError("Can not be represented by a double"); |
| 177 | |
| 178 | return Struct.unpack(Struct.float64, bytes); |
| 179 | }; |
| 180 | |
| 181 | this.asInteger = function () { |
| 182 | if (bytes[7] != 0 || bytes[6] > 0x20) { |