This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function nmadd(a, b, p) { | |
| const at = (2**27 + 1) * a; | |
| const ahi = at - (at - a); | |
| const alo = a - ahi; | |
| const bt = (2**27 + 1) * b; | |
| const bhi = bt - (bt - b); | |
| const blo = b - bhi; | |
| return ((p - ahi * bhi) - ahi * blo - alo * bhi) - alo * blo; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const e = B2 >= 10**7 && d * d < 2**53 ? 2 : 1; | |
| const dsP = scalePoint(curve, sP, Math.pow(d, e)); | |
| const range = function (n) { | |
| const a = new Array(n); | |
| for (let i = 0; i < n; i += 1) { | |
| a[i] = i; | |
| } | |
| return a; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add(a, b) { | |
| const c = new Array(Math.max(a.length, b.length)); | |
| const min = Math.min(a.length, b.length); | |
| for (let i = 0; i < min; i += 1) { | |
| c[i] = a[i] + b[i]; | |
| } | |
| for (let i = min; i < a.length; i += 1) { | |
| c[i] = a[i]; | |
| } | |
| for (let i = min; i < b.length; i += 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let hex = new Uint8Array(0); | |
| const td = new TextDecoder(); | |
| const te = new TextEncoder(); | |
| function packBigInt(blocks, blockSize) { | |
| function encode(blocks, length) { | |
| const u32 = new Uint32Array(hex.buffer); | |
| let k = (length >> 2) - 1;//TODO:!? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const uint64 = new BigUint64Array(1); | |
| const uint32 = new Uint32Array(uint64.buffer); | |
| function clz64(bigint) { | |
| uint64[0] = bigint; | |
| let x = Math.clz32(uint32[1]); | |
| let y = Math.clz32(uint32[0]); | |
| return x + (x === 32 ? y : 0); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*jshint esversion:6, bitwise:false*/ | |
| // https://webassembly.github.io/wabt/demo/wat2wasm/index.html helps a lot | |
| function wast2wasm(sExpression) { | |
| function sExpressionToJSON(s) { | |
| return JSON.parse(s.trim().replace(/\s*\)/g, ']').replace(/\(\s*/g, '[').replace(/\s+/g, ',').replaceAll('"', '').replace(/([^\[\],]+)/g, '"$1"')); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CPU L2 cache size | |
| function ASMModule1(stdlib, foreign, heap) { | |
| "use asm"; | |
| var memory = new stdlib.Uint32Array(heap); | |
| function loop(c) { | |
| c = c | 0; | |
| var k = 0; | |
| var j = 0; | |
| for (j = c; (j | 0) != 0; j = (j - 1) | 0) { | |
| k = memory[k >> 2] << 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function* continuedFractionForSqrt(n) { | |
| // https://trizenx.blogspot.com/2018/10/continued-fraction-factorization-method.html | |
| function floorDiv(a, b) { | |
| return typeof a === "bigint" && typeof b === "bigint" ? a / b : Math.floor(a / b); | |
| } | |
| n = BigInt(n); | |
| if (n < 0n) { | |
| throw new RangeError(); | |
| } | |
| const root = BigInt(sqrt(n)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Usage: | |
| // var x = document.querySelector('[contenteditable]'); | |
| // var caretPosition = getSelectionDirection(x) !== 'forward' ? getSelectionStart(x) : getSelectionEnd(x); | |
| // setSelectionRange(x, caretPosition + 1, caretPosition + 1); | |
| // var value = getValue(x); | |
| // it will not work with "<img /><img />" and, perhaps, in many other cases. | |
| function isAfter(container, offset, node) { | |
| var c = node; |
NewerOlder