feat: Implement signature-specifc reference
Also implements a config object that upon change, lazily invalidates all operations that access it. Also allows references to signatures with nonexistent types (which typed-function does not); they come back as undefined. Uses these features to implement sqrt for number and complex. Resolves #7.
This commit is contained in:
parent
79f261ff65
commit
91ec20edd8
21 changed files with 256 additions and 26 deletions
0
test/complex/##
Executable file
0
test/complex/##
Executable file
29
test/complex/_all.mjs
Normal file
29
test/complex/_all.mjs
Normal file
|
@ -0,0 +1,29 @@
|
|||
import assert from 'assert'
|
||||
import math from '../../src/pocomath.mjs'
|
||||
import PocomathInstance from '../../src/core/PocomathInstance.mjs'
|
||||
import * as complexSqrt from '../../src/complex/sqrt.mjs'
|
||||
|
||||
describe('complex', () => {
|
||||
it('supports sqrt', () => {
|
||||
assert.deepStrictEqual(math.sqrt(math.complex(1,0)), 1)
|
||||
assert.deepStrictEqual(
|
||||
math.sqrt(math.complex(0,1)),
|
||||
math.complex(math.sqrt(0.5), math.sqrt(0.5)))
|
||||
math.config.predictable = true
|
||||
assert.deepStrictEqual(math.sqrt(math.complex(1,0)), math.complex(1,0))
|
||||
assert.deepStrictEqual(
|
||||
math.sqrt(math.complex(0,1)),
|
||||
math.complex(math.sqrt(0.5), math.sqrt(0.5)))
|
||||
math.config.predictable = false
|
||||
})
|
||||
|
||||
it('can bundle sqrt', async function () {
|
||||
const ms = new PocomathInstance('Minimal Sqrt')
|
||||
ms.install(complexSqrt)
|
||||
await ms.importDependencies(['number', 'complex'])
|
||||
assert.deepStrictEqual(
|
||||
ms.sqrt(math.complex(0, -1)),
|
||||
math.complex(ms.negate(ms.sqrt(0.5)), ms.sqrt(0.5)))
|
||||
})
|
||||
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue