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
1
src/generic/all.mjs
Normal file
1
src/generic/all.mjs
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './arithmetic.mjs'
|
3
src/generic/arithmetic.mjs
Normal file
3
src/generic/arithmetic.mjs
Normal file
|
@ -0,0 +1,3 @@
|
|||
export {divide} from './divide.mjs'
|
||||
export {sign} from './sign.mjs'
|
||||
export {subtract} from './subtract.mjs'
|
4
src/generic/divide.mjs
Normal file
4
src/generic/divide.mjs
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const divide = {
|
||||
'any,any': ({multiply, invert}) => (x, y) => multiply(x, invert(y))
|
||||
}
|
||||
|
6
src/generic/sign.mjs
Normal file
6
src/generic/sign.mjs
Normal file
|
@ -0,0 +1,6 @@
|
|||
export const sign = {
|
||||
any: ({negate, divide, abs}) => x => {
|
||||
if (x === negate(x)) return x // zero
|
||||
return divide(x, abs(x))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue