Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 31x 31x 31x 102x 24x 24x 31x 11x 1x 1x 31x 31x 31x 248x 248x 288x 288x 288x 288x 288x 31x 31x | /** * @file Complex number operations * @module Complex */ require('./monkey-patch.js'); let Complex = require('complex.js'); /** * Checks if the current complex number is less than the given complex number. * @param {Complex} other - The complex number to compare with. * @returns {boolean} - Returns true if the current complex number is less than the given complex number, otherwise returns false. */ Complex.prototype.lessThan = function (other) { if (this.re < other.re) return true; Iif (this.re == other.re && this.im < other.im) return true; return false; } /** * Checks if the current complex number is greater than the given complex number. * @param {Complex} other - The complex number to compare with. * @returns {boolean} - Returns true if the current complex number is greater than the given complex number, otherwise returns false. */ Complex.prototype.greaterThan = function (other) { if (this.re > other.re) return true; Iif (this.re == other.re && this.im > other.im) return true; return false; } /** * Set of supported operators. * @type {Set<string>} */ let Operators = new Set(['add', 'sub', 'mul', 'div', 'equals', 'pow', 'neg', 'lessThan']) let oldComplex = Object.create(null); for (let op of Operators) { oldComplex[op] = Complex.prototype[op]; /** * Overrides the operator method for complex numbers. * @param {Complex|function|boolean|string} other - The operand to perform the operation with. * @returns {*} - The result of the operation. * @throws {Error} - Throws an error if the operation is not supported for the given operand. */ Complex.prototype[op] = function (other) { try { Iif (typeof other === 'function') return other[op](this); Iif (typeof other === 'boolean') return this[op](Complex(Number(other))); Iif (typeof other === 'string') return String(this) [op](other); return oldComplex[op].call(this, other) } catch (e) { throw new Error(`Complex numbers do not support ${op} for ${other}\n${e}`) } } } /** * Returns the current complex number. * @param {*} other - Ignored parameter. * @returns {Complex} - The current complex number. */ Complex.prototype.call = function (other) { return this } module.exports = Complex; |