This file contains 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
/*jslint plusplus: true, vars: true, indent: 2 */ | |
/* | |
convertPointFromPageToNode(element, event.pageX, event.pageY) -> {x, y} | |
returns coordinate in element's local coordinate system (works properly with css transforms without perspective projection) | |
convertPointFromNodeToPage(element, offsetX, offsetY) -> {x, y} | |
returns coordinate in window's coordinate system (works properly with css transforms without perspective projection) | |
*/ |
This file contains 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
// a * b + c | |
// Math.fma - fused multiply–add (FMA) or fused multiply–accumulate (FMAC) in JavaScript | |
// For implementation details, see "The Handbook of Applied Cryptography" | |
// http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf | |
// and | |
// https://github.com/JuliaLang/openlibm/blob/master/src/s_fma.c | |
//!? BUGGY | |
(function () { |
This file contains 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 crc32(s/*, polynomial = 0x04C11DB7, initialValue = 0xFFFFFFFF, finalXORValue = 0xFFFFFFFF*/) { | |
s = String(s); | |
var polynomial = arguments.length < 2 ? 0x04C11DB7 : (arguments[1] >>> 0); | |
var initialValue = arguments.length < 3 ? 0xFFFFFFFF : (arguments[2] >>> 0); | |
var finalXORValue = arguments.length < 4 ? 0xFFFFFFFF : (arguments[3] >>> 0); | |
var table = new Array(256); | |
var reverse = function (x, n) { | |
var b = 0; |
This file contains 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
// TextEncoder/TextDecoder polyfills for utf-8 - an implementation of TextEncoder/TextDecoder APIs | |
// Written in 2013 by Viktor Mukhachev <vic99999@yandex.ru> | |
// To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. | |
// You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | |
// Some important notes about the polyfill below: | |
// Native TextEncoder/TextDecoder implementation is overwritten | |
// String.prototype.codePointAt polyfill not included, as well as String.fromCodePoint | |
// TextEncoder.prototype.encode returns a regular array instead of Uint8Array | |
// No options (fatal of the TextDecoder constructor and stream of the TextDecoder.prototype.decode method) are supported. |
This file contains 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 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 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 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 setVisibleTimeout(callback, delay) { | |
var id = null, | |
t = 0, | |
prefix = ''; | |
'o webkit moz ms'.replace(/\S+/g, function (p) { | |
if ((p + 'Hidden') in document) { | |
prefix = p; | |
} | |
}); | |
function onVisibilityChange(event) { |
This file contains 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
/*jslint regexp: true, maxerr: 50, indent: 2 */ | |
(function (global) { | |
"use strict"; | |
function URLUtils(url, baseURL) { | |
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); | |
if (!m) { | |
throw new RangeError(); | |
} |
This file contains 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)); |
NewerOlder