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:
Glen Whitney 2022-07-25 04:20:13 -07:00
parent 79f261ff65
commit 91ec20edd8
21 changed files with 256 additions and 26 deletions

14
src/number/sqrt.mjs Normal file
View file

@ -0,0 +1,14 @@
export { Types } from './Types/number.mjs'
export const sqrt = {
number: ({config, complex, 'self(Complex)': complexSqrt}) => {
if (config.predictable || !complexSqrt) {
return n => isNaN(n) ? NaN : Math.sqrt(n)
}
return n => {
if (isNaN(n)) return NaN
if (n >= 0) return Math.sqrt(n)
return complexSqrt(complex(n))
}
}
}