Minor fixes

This commit is contained in:
Schmelczer András 2020-01-08 22:22:26 +01:00
parent 073f087e52
commit aa0906405c
19 changed files with 219 additions and 174 deletions

View file

@ -0,0 +1,5 @@
export const turnOnAnimations = () =>
document.body.parentElement.setAttribute('animations', 'on');
export const turnOffAnimations = () =>
document.body.parentElement.setAttribute('animations', 'off');

View file

@ -0,0 +1,17 @@
export const addImul = () => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
if (!Math.imul)
Math.imul = function(opA, opB) {
opB |= 0; // ensure that opB is an integer. opA will automatically be coerced.
// floating points give us 53 bits of precision to work with plus 1 sign bit
// automatically handled for our convenience:
// 1. 0x003fffff /*opA & 0x000fffff*/ * 0x7fffffff /*opB*/ = 0x1fffff7fc00001
// 0x1fffff7fc00001 < Number.MAX_SAFE_INTEGER /*0x1fffffffffffff*/
let result = (opA & 0x003fffff) * opB;
// 2. We can remove an integer coercion from the statement above because:
// 0x1fffff7fc00001 + 0xffc00000 = 0x1fffffff800001
// 0x1fffffff800001 < Number.MAX_SAFE_INTEGER /*0x1fffffffffffff*/
if (opA & 0xffc00000 /*!== 0*/) result += ((opA & 0xffc00000) * opB) | 0;
return result | 0;
};
};

View file

@ -1,4 +1,4 @@
import { addImul } from '../polyfills';
import { addImul } from './polyfills';
export class Random {
public constructor(private seed: number) {