mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +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>
119 lines
5.0 KiB
JavaScript
119 lines
5.0 KiB
JavaScript
import assert from 'assert'
|
|
import math from '../../../../src/defaultInstance.js'
|
|
import approx from '../../../../tools/approx.js'
|
|
const complex = math.complex
|
|
const matrix = math.matrix
|
|
const unit = math.unit
|
|
const sinh = math.sinh
|
|
const bigmath = math.create({ number: 'BigNumber', precision: 20 })
|
|
|
|
const EPSILON = 1e-14
|
|
|
|
describe('sinh', function () {
|
|
it('should return the sinh of a boolean', function () {
|
|
assert.strictEqual(sinh(true), 1.1752011936438014)
|
|
assert.strictEqual(sinh(false), 0)
|
|
})
|
|
|
|
it('should return the sinh of a number', function () {
|
|
approx.equal(sinh(-2), -3.62686040784701876766821398280126170488634201232113572130, EPSILON)
|
|
approx.equal(sinh(-0.5), -0.52109530549374736162242562641149155910592898261148052794, EPSILON)
|
|
approx.equal(sinh(0), 0, EPSILON)
|
|
approx.equal(sinh(0.3), 0.304520293447142618958435267005095229098024232680179727377, EPSILON)
|
|
approx.equal(sinh(0.5), 0.521095305493747361622425626411491559105928982611480527946, EPSILON)
|
|
approx.equal(sinh(0.8), 0.888105982187623006574717573189756980559709596888150052610, EPSILON)
|
|
approx.equal(sinh(1), 1.175201193643801456882381850595600815155717981334095870229, EPSILON)
|
|
approx.equal(sinh(2), 3.626860407847018767668213982801261704886342012321135721309, EPSILON)
|
|
})
|
|
|
|
if (process.version !== '' && !/v0\.10|v0\.12/.test(process.version)) {
|
|
// we only do these tests on node.js
|
|
// skip this test on node v0.10 and v0.12 and IE 11, which have a numerical issue
|
|
|
|
it('should return the sinh of very small numbers (avoid returning zero)', function () {
|
|
// If sinh returns 0, that is bad, so we are using assert, not approx.equal
|
|
assert(sinh(-1e-10) !== 0)
|
|
assert(Math.abs(sinh(-1e-10) - -1e-10) < EPSILON)
|
|
})
|
|
|
|
it('should return the sinh of very large numbers (avoid returning zero)', function () {
|
|
// If sinh returns 0, that is bad, so we are using assert.strictEqual, not approx.equal
|
|
// console.log('process.version=', process.version)
|
|
assert(sinh(1e-50) !== 0)
|
|
assert(Math.abs(sinh(1e-50) - 1e-50) < EPSILON)
|
|
})
|
|
}
|
|
|
|
it('should return the sinh of a bignumber', function () {
|
|
const sinhBig = bigmath.sinh
|
|
const Big = bigmath.bignumber
|
|
|
|
const arg1 = Big(-Infinity)
|
|
const arg2 = Big(-1)
|
|
const arg7 = Big(Infinity)
|
|
assert.deepStrictEqual(sinhBig(arg1).toString(), '-Infinity')
|
|
assert.deepStrictEqual(sinhBig(arg2), Big('-1.1752011936438014569'))
|
|
assert.deepStrictEqual(sinhBig(Big(-1e-10)), Big(-1e-10))
|
|
assert.deepStrictEqual(sinhBig(Big(0)), Big(0))
|
|
assert.deepStrictEqual(sinhBig(Big(1)), Big('1.1752011936438014569'))
|
|
assert.deepStrictEqual(sinhBig(bigmath.pi).toString(), '11.548739357257748378')
|
|
assert.deepStrictEqual(sinhBig(arg7).toString(), 'Infinity')
|
|
|
|
// Ensure args were not changed
|
|
assert.deepStrictEqual(arg1.toString(), '-Infinity')
|
|
assert.deepStrictEqual(arg2, Big(-1))
|
|
assert.deepStrictEqual(arg7.toString(), 'Infinity')
|
|
|
|
bigmath.config({ precision: 50 })
|
|
assert.deepStrictEqual(sinhBig(Big(1e-50)), Big(1e-50))
|
|
})
|
|
|
|
it('should return the sinh of a complex number', function () {
|
|
approx.deepEqual(sinh(complex('1')), complex(1.1752011936438014, 0), EPSILON)
|
|
approx.deepEqual(sinh(complex('i')), complex(0, 0.8414709848079), EPSILON)
|
|
approx.deepEqual(sinh(complex('2 + i')), complex(1.9596010414216, 3.1657785132162), EPSILON)
|
|
})
|
|
|
|
it('should return the sinh of an angle', function () {
|
|
approx.equal(sinh(unit('90deg')), 2.3012989023073, EPSILON)
|
|
approx.equal(sinh(unit('-45deg')), -0.86867096148601, EPSILON)
|
|
|
|
assert(math.isBigNumber(sinh(unit(math.bignumber(90), 'deg'))))
|
|
approx.equal(sinh(unit(math.bignumber(90), 'deg')).toNumber(), 2.3012989023073, EPSILON)
|
|
|
|
approx.deepEqual(sinh(unit(complex('2 + i'), 'rad')), complex(1.9596010414216, 3.1657785132162), EPSILON)
|
|
})
|
|
|
|
it('should throw an error if called with an invalid unit', function () {
|
|
assert.throws(function () { sinh(unit('5 celsius')) })
|
|
})
|
|
|
|
it('should throw an error if called with a string', function () {
|
|
assert.throws(function () { sinh('string') })
|
|
})
|
|
|
|
const sinh123 = [1.1752011936438014, 3.626860407847, 10.01787492741]
|
|
|
|
it('should return the sinh of each element of an array', function () {
|
|
approx.deepEqual(sinh([1, 2, 3]), sinh123, EPSILON)
|
|
})
|
|
|
|
it('should return the sinh of each element of a matrix', function () {
|
|
approx.deepEqual(sinh(matrix([1, 2, 3])), matrix(sinh123), EPSILON)
|
|
})
|
|
|
|
it('should throw an error in case of invalid number of arguments', function () {
|
|
assert.throws(function () { sinh() }, /TypeError: Too few arguments/)
|
|
assert.throws(function () { sinh(1, 2) }, /TypeError: Too many arguments/)
|
|
})
|
|
|
|
it('should throw an error in case of invalid type of arguments', function () {
|
|
assert.throws(function () { sinh(null) }, /TypeError: Unexpected type of argument/)
|
|
})
|
|
|
|
it('should LaTeX sinh', function () {
|
|
const expression = math.parse('sinh(1)')
|
|
assert.strictEqual(expression.toTex(), '\\sinh\\left(1\\right)')
|
|
})
|
|
})
|