UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

43 lines (38 loc) 1.42 kB
'use strict'; var nearlyEqual = require('../../utils/number').nearlyEqual; var bigNearlyEqual = require('../../utils/bignumber/nearlyEqual'); function factory(type, config, load, typed) { /** * Test whether two values are equal. * * @param {number | BigNumber | Fraction | boolean | Complex | Unit} x First value to compare * @param {number | BigNumber | Fraction | boolean | Complex} y Second value to compare * @return {boolean} Returns true when the compared values are equal, else returns false * @private */ var equalScalar = typed('equalScalar', { 'boolean, boolean': function booleanBoolean(x, y) { return x === y; }, 'number, number': function numberNumber(x, y) { return x === y || nearlyEqual(x, y, config.epsilon); }, 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) { return x.eq(y) || bigNearlyEqual(x, y, config.epsilon); }, 'Fraction, Fraction': function FractionFraction(x, y) { return x.equals(y); }, 'Complex, Complex': function ComplexComplex(x, y) { return x.equals(y); }, 'Unit, Unit': function UnitUnit(x, y) { if (!x.equalBase(y)) { throw new Error('Cannot compare units with different base'); } return equalScalar(x.value, y.value); } }); return equalScalar; } exports.factory = factory;