(value)
| 299 | // value, represented by a low and high i32 pair. |
| 300 | // Will suffer from rounding and truncation. |
| 301 | function splitI64(value) { |
| 302 | if (WASM_BIGINT) { |
| 303 | // Nothing to do: just make sure it is a BigInt (as it must be of that |
| 304 | // type, to be sent into wasm). |
| 305 | return castToBigInt(value); |
| 306 | } |
| 307 | |
| 308 | // general idea: |
| 309 | // |
| 310 | // $1$0 = ~~$d >>> 0; |
| 311 | // $1$1 = Math.abs($d) >= 1 ? ( |
| 312 | // $d > 0 ? Math.floor(($d)/ 4294967296.0) >>> 0 |
| 313 | // : Math.ceil(Math.min(-4294967296.0, $d - $1$0)/ 4294967296.0) |
| 314 | // ) : 0; |
| 315 | // |
| 316 | // We need to min on positive values here, since our input might be a double, |
| 317 | // and large values are rounded, so they can be slightly higher than expected. |
| 318 | // And if we get 4294967296, that will turn into a 0 if put into a HEAP32 or |
| 319 | // |0'd, etc. |
| 320 | // |
| 321 | // For negatives, we need to ensure a -1 if the value is overall negative, |
| 322 | // even if not significant negative component |
| 323 | |
| 324 | const low = value + '>>>0'; |
| 325 | // prettier-ignore |
| 326 | const high = makeInlineCalculation( |
| 327 | asmCoercion('Math.abs(VALUE)', 'double') + ' >= ' + asmEnsureFloat('1', 'double') + ' ? ' + |
| 328 | '(VALUE > ' + asmEnsureFloat('0', 'double') + ' ? ' + |
| 329 | asmCoercion('Math.floor((VALUE)/' + |
| 330 | asmEnsureFloat(4294967296, 'double') + ')', 'double') + '>>>0' + |
| 331 | ' : ' + |
| 332 | asmFloatToInt(asmCoercion('Math.ceil((VALUE - +((' + asmFloatToInt('VALUE') + ')>>>0))/' + |
| 333 | asmEnsureFloat(4294967296, 'double') + ')', 'double')) + '>>>0' + |
| 334 | ')' + |
| 335 | ' : 0', |
| 336 | value, |
| 337 | 'tempDouble', |
| 338 | ); |
| 339 | return [low, high]; |
| 340 | } |
| 341 | |
| 342 | // Misc |
| 343 |
no test coverage detected