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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Math.cbrt #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Math.trunc vs Math.floor #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
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
// `Array#sort` implementation using the merge sort | |
// Notes: | |
// 1) calls comparator for undefined values, holes, values from the prototype chain; | |
// 2*) replaces holes with undefined values or values from the prototype chain; | |
// 3*) does not use `ToObject(this)`, `ToLength(this.length)`; | |
// 4*) does not throw errors for non-undefined non-function `comparefn`. | |
// 5*) uses `Math`, `Math.floor`, `String`, `Array`. | |
// 6*) calls setters of `Array.prototype` during internal buffer initialization. | |
// * This behaviour is inconsistent across browsers even for built-in `Array#sort`. |
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
var drawArrow = function (context, x1, y1, x2, y2) { | |
context.lineWidth = 1.25; | |
context.beginPath(); | |
context.moveTo(x1, y1); | |
context.lineTo(x2, y2); | |
context.stroke(); | |
var a = Math.PI / 8; | |
var h = 12; | |
var sa = Math.sin(a); |
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
// (Math.exp(704.6589) / Math.expm1(704.6589) - 1) / Number.EPSILON | |
var isExpOK = Math.exp(704.6589) >= 1.0702171200481775e+306 * (1 - 16 * Math.pow(2, -52)) && | |
Math.exp(704.6589) <= 1.0702171200481775e+306 * (1 + 16 * Math.pow(2, -52)); | |
// (Math.exp(704.6589) / Math.expm1(704.6589) - 1) / Number.EPSILON | |
var isExpOK = Math.exp(704.6589) >= 1.0702171200481775e+306 * (1 - 16 * Math.pow(2, -52)) && | |
Math.exp(704.6589) <= 1.0702171200481775e+306 * (1 + 16 * Math.pow(2, -52)); | |
Math.exp = function (x) { | |
var hi = 0.6931471805598903; | |
var lo = 5.497923018708371e-14; | |
var k = Math.floor(x / hi + 0.5); |
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
"use strict"; | |
function URLSearchParams(query) { | |
var data = []; | |
query = query.toString(); | |
query = query.replace(/\+/g, " "); | |
var strings = query.split("&"); | |
var l = strings.length; | |
var i = 0; | |
while (i < l) { |
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
markup.doc = document.implementation.createHTMLDocument ? document.implementation.createHTMLDocument("") : null; | |
function markup(s) { | |
var doc = markup.doc; | |
var div = null; | |
if (doc === null) { | |
div = document.createElement("div"); | |
if (window.toStaticHTML) {// IE 8 | |
div.innerHTML = window.toStaticHTML(s); | |
} else { |
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
<script> | |
var timeZoneIds = [ | |
"Africa/Abidjan", | |
"Africa/Accra", | |
"Africa/Addis_Ababa", | |
"Africa/Algiers", | |
"Africa/Asmera", | |
"Africa/Bamako", | |
"Africa/Bangui", |
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
<script> | |
var whiteList = ["http://localhost", "http://hostel6.ru", "http://yandex.ru"]; | |
window.addEventListener("message", function (e) { | |
var origin = e.origin; | |
var i = whiteList.length; | |
var ok = false; | |
while (--i >= 0) { | |
if (whiteList[i] === origin) { | |
ok = true; |