UNPKG

bigfloat

Version:

Fast arbitrary precision math library for computational geometry.

108 lines (107 loc) 4.09 kB
// This file is part of bigfloat, copyright (c) 2018- BusFaster Ltd. // Released under the MIT license, see LICENSE. import { BigFloat32 } from './BigFloat32'; import { BigFloat53 } from './BigFloat53'; /** Simpler replacement for the default TypeScript helper. * Ignores static members and avoids rollup warnings. */ function __extends(child, parent) { function helper() { this.constructor = child; } helper.prototype = parent.prototype; child.prototype = new helper(); } var BigComplex = /** @class */ (function () { function BigComplex(real, imag, base) { this.real = typeof (real) == 'object' ? real : new this.Base(real, base); this.imag = typeof (imag) == 'object' ? imag : new this.Base(imag, base); } BigComplex.prototype.clone = function () { var other = new this.constructor(this.real.clone(), this.imag.clone()); return (other); }; BigComplex.prototype.setZero = function () { this.real.setZero(); this.imag.setZero(); return (this); }; BigComplex.prototype.setValue = function (other) { this.real.setValue(other.real); this.imag.setValue(other.imag); return (this); }; BigComplex.prototype.mul = function (multiplier, product) { product = product || new this.constructor(); if (multiplier instanceof BigComplex) { this.real.mul(multiplier.real, this.temp1); this.imag.mul(multiplier.imag, this.temp2); this.temp1.sub(this.temp2, product.real); this.real.mul(multiplier.imag, this.temp1); this.imag.mul(multiplier.real, this.temp2); this.temp1.add(this.temp2, product.imag); } else { this.real.mul(multiplier, product.real); this.imag.mul(multiplier, product.imag); } return (product); }; BigComplex.prototype.sqr = function (product) { product = product || new this.constructor(); this.real.mul(this.real, this.temp1); this.imag.mul(this.imag, this.temp2); this.temp1.sub(this.temp2, product.real); this.real.mul(this.imag, this.temp1); this.temp1.add(this.temp1, product.imag); return (product); }; BigComplex.prototype.add = function (addend, sum) { sum = sum || new this.constructor(); if (addend instanceof BigComplex) { this.real.add(addend.real, sum.real); this.imag.add(addend.imag, sum.imag); } else { this.real.add(addend, sum.real); } return (sum); }; BigComplex.prototype.sub = function (subtrahend, difference) { difference = difference || new this.constructor(); if (subtrahend instanceof BigComplex) { this.real.sub(subtrahend.real, difference.real); this.imag.sub(subtrahend.imag, difference.imag); } else { this.real.sub(subtrahend, difference.real); } return (difference); }; BigComplex.prototype.truncate = function (fractionLimbCount) { this.real.truncate(fractionLimbCount); this.imag.truncate(fractionLimbCount); return (this); }; return BigComplex; }()); export { BigComplex }; var BigComplex32 = /** @class */ (function (_super) { __extends(BigComplex32, _super); function BigComplex32() { return _super !== null && _super.apply(this, arguments) || this; } return BigComplex32; }(BigComplex)); export { BigComplex32 }; var BigComplex53 = /** @class */ (function (_super) { __extends(BigComplex53, _super); function BigComplex53() { return _super !== null && _super.apply(this, arguments) || this; } return BigComplex53; }(BigComplex)); export { BigComplex53 }; BigComplex32.prototype.Base = BigFloat32; BigComplex32.prototype.temp1 = new BigFloat32(); BigComplex32.prototype.temp2 = new BigFloat32(); BigComplex53.prototype.Base = BigFloat53; BigComplex53.prototype.temp1 = new BigFloat53(); BigComplex53.prototype.temp2 = new BigFloat53();