mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
* Add `.js` extension to source file imports * Specify package `exports` in `package.json` Specify package type as `commonjs` (It's good to be specific) * Move all compiled scripts into `lib` directory Remove ./number.js (You can use the compiled ones in `./lib/*`) Tell node that the `esm` directory is type `module` and enable tree shaking. Remove unused files from packages `files` property * Allow importing of package.json * Make library ESM first * - Fix merge conflicts - Refactor `bundleAny` into `defaultInstance.js` and `browserBundle.cjs` - Refactor unit tests to be able to run with plain nodejs (no transpiling) - Fix browser examples * Fix browser and browserstack tests * Fix running unit tests on Node 10 (which has no support for modules) * Fix node.js examples (those are still commonjs) * Remove the need for `browserBundle.cjs` * Generate minified bundle only * [Security] Bump node-fetch from 2.6.0 to 2.6.1 (#1963) Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. **This update includes a security fix.** - [Release notes](https://github.com/bitinn/node-fetch/releases) - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Cleanup console.log * Add integration tests to test the entry points (commonjs/esm, full/number only) * Create backward compatibility error messages in the files moved/removed since v8 * Describe breaking changes in HISTORY.md * Bump karma from 5.2.1 to 5.2.2 (#1965) Bumps [karma](https://github.com/karma-runner/karma) from 5.2.1 to 5.2.2. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v5.2.1...v5.2.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Lee Langley-Rees <lee@greenimp.co.uk> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
92 lines
4.0 KiB
JavaScript
92 lines
4.0 KiB
JavaScript
// test expm1
|
|
import assert from 'assert'
|
|
|
|
import approx from '../../../../tools/approx.js'
|
|
import math from '../../../../src/defaultInstance.js'
|
|
const complex = math.complex
|
|
const matrix = math.matrix
|
|
const sparse = math.sparse
|
|
const unit = math.unit
|
|
const expm1 = math.expm1
|
|
|
|
describe('expm1', function () {
|
|
it('should exponentiate a boolean', function () {
|
|
approx.equal(expm1(true), 1.71828182845905)
|
|
approx.equal(expm1(false), 0)
|
|
})
|
|
|
|
it('should exponentiate a number', function () {
|
|
approx.equal(expm1(-3), -0.9502129316321360)
|
|
approx.equal(expm1(-2), -0.8646647167633873)
|
|
approx.equal(expm1(-1), -0.6321205588285577)
|
|
approx.equal(expm1(0), 0)
|
|
approx.equal(expm1(1), 1.71828182845905)
|
|
approx.equal(expm1(2), 6.38905609893065)
|
|
approx.equal(expm1(3), 19.0855369231877)
|
|
approx.equal(expm1(math.log(100)) + 1, 100)
|
|
|
|
// function requirements
|
|
assert.ok(isNaN(expm1(NaN)))
|
|
assert.strictEqual(expm1(+0), 0)
|
|
assert.strictEqual(expm1(-0), -0)
|
|
assert.strictEqual(expm1(+Infinity), Infinity)
|
|
assert.strictEqual(expm1(-Infinity), -1)
|
|
})
|
|
|
|
it('should exponentiate a bignumber', function () {
|
|
const bigmath = math.create({ precision: 100 })
|
|
|
|
assert.deepStrictEqual(bigmath.expm1(bigmath.bignumber(1)), bigmath.bignumber('1.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427'))
|
|
})
|
|
|
|
it('should throw an error if there\'s wrong number of arguments', function () {
|
|
assert.throws(function () { expm1() }, /TypeError: Too few arguments/)
|
|
assert.throws(function () { expm1(1, 2) }, /TypeError: Too many arguments/)
|
|
})
|
|
|
|
it('should exponentiate a complex number correctly', function () {
|
|
approx.deepEqual(expm1(math.i), complex('-0.45969769413186 + 0.841470984807897i'))
|
|
approx.deepEqual(expm1(complex(0, -1)), complex('-0.45969769413186 - 0.841470984807897i'))
|
|
approx.deepEqual(expm1(complex(1, 1)), complex('0.46869393991589 + 2.28735528717884i'))
|
|
approx.deepEqual(expm1(complex(1, -1)), complex('0.46869393991589 - 2.28735528717884i'))
|
|
approx.deepEqual(expm1(complex(-1, -1)), complex('-0.80123388965359 - 0.309559875653112i'))
|
|
approx.deepEqual(expm1(complex(-1, 1)), complex('-0.80123388965359 + 0.309559875653112i'))
|
|
approx.deepEqual(expm1(complex(1, 0)), complex('1.71828182845905'))
|
|
|
|
// test some logic identities
|
|
const multiply = math.multiply
|
|
const pi = math.pi
|
|
const i = math.i
|
|
approx.deepEqual(expm1(multiply(0.5, multiply(pi, i))), complex(-1, 1))
|
|
approx.deepEqual(expm1(multiply(1, multiply(pi, i))), complex(-2, 0))
|
|
approx.deepEqual(expm1(multiply(1.5, multiply(pi, i))), complex(-1, -1))
|
|
approx.deepEqual(expm1(multiply(2, multiply(pi, i))), complex(0, 0))
|
|
approx.deepEqual(expm1(multiply(-0.5, multiply(pi, i))), complex(-1, -1))
|
|
approx.deepEqual(expm1(multiply(-1, multiply(pi, i))), complex(-2, 0))
|
|
approx.deepEqual(expm1(multiply(-1.5, multiply(pi, i))), complex(-1, 1))
|
|
})
|
|
|
|
it('should throw an error on a unit', function () {
|
|
assert.throws(function () { expm1(unit('5cm')) })
|
|
})
|
|
|
|
it('should throw an error with a string', function () {
|
|
assert.throws(function () { expm1('text') })
|
|
})
|
|
|
|
it('should exponentiate matrices, arrays and ranges correctly', function () {
|
|
// array
|
|
approx.deepEqual(expm1([0, 1, 2, 3]), [0, 1.71828182845905, 6.38905609893065, 19.0855369231877])
|
|
approx.deepEqual(expm1([[0, 1], [2, 3]]), [[0, 1.71828182845905], [6.38905609893065, 19.0855369231877]])
|
|
// dense matrix
|
|
approx.deepEqual(expm1(matrix([0, 1, 2, 3])), matrix([0, 1.71828182845905, 6.38905609893065, 19.0855369231877]))
|
|
approx.deepEqual(expm1(matrix([[0, 1], [2, 3]])), matrix([[0, 1.71828182845905], [6.38905609893065, 19.0855369231877]]))
|
|
approx.deepEqual(expm1(sparse([[0, 1], [2, 3]])), sparse([[0, 1.71828182845905], [6.38905609893065, 19.0855369231877]]))
|
|
})
|
|
|
|
it('should LaTeX expm1', function () {
|
|
const expression = math.parse('expm1(0)')
|
|
assert.strictEqual(expression.toTex(), '\\left(e^{0}-1\\right)')
|
|
})
|
|
})
|