UNPKG

bigfloat

Version:

Fast arbitrary precision math library for computational geometry.

30 lines (29 loc) 1.25 kB
// This file is part of bigfloat, copyright (c) 2015- BusFaster Ltd. // Released under the MIT license, see LICENSE. /** Base for calculations, the bigger the better but must fit in 32 bits. */ export var limbSize32 = Math.pow(2, 32); export var limbInv32 = Math.pow(2, -32); export var limbsPerDigit32 = Math.log(10) / (32 * Math.log(2)); /** Create a string with the given number of zero digits. */ function zeroes(count) { return (new Array(count + 1).join('0')); } var BaseInfo32 = /** @class */ (function () { function BaseInfo32(base) { this.base = base; /** Average number of digits per limb. */ this.limbDigitsExact = Math.log(limbSize32) / Math.log(this.base); /** Number of entire digits per limb. */ this.limbDigits = ~~this.limbDigitsExact; /** Maximum power of base that fits in a limb. */ this.limbBase = Math.pow(this.base, this.limbDigits); /** String of zeroes for padding an empty limb. */ this.pad = zeroes(this.limbDigits); } BaseInfo32.init = function (base) { return (BaseInfo32.baseTbl[base] || (BaseInfo32.baseTbl[base] = new BaseInfo32(base))); }; BaseInfo32.baseTbl = {}; return BaseInfo32; }()); export { BaseInfo32 };