fix(Types): Move distinct types into distinct identifiers

This allows types to be collected; prior to this commit they
   were conflicting from different modules.

   Uses this fix to extend sqrt to bigint, with the convention
   that it is undefined for non-perfect squares when 'predictable'
   is false and is the "best" approximation to the square root when
   'predictable' is true. Furthermore, for negative bigints, you might
   get a Gaussian integer when predictable is false; or you will just get
   your argument back when 'predictable' is true because what other
   bigint could you give back for a negative bigint?

   Also had to modify tests on the sign in sqrt(Complex) and add functions
   'zero' and 'one' to get types to match, as expected in #27.

   Adds numerous tests.

   Resolves #26.
   Resolves #27.
This commit is contained in:
Glen Whitney 2022-07-25 11:56:12 -07:00
parent b21d2b59fa
commit f68c7bd1fb
44 changed files with 287 additions and 109 deletions

View file

@ -0,0 +1,2 @@
export const Type_undefined = {test: u => u === undefined}

View file

@ -1,3 +1,7 @@
export * from './Types/generic.mjs'
export {multiply} from './multiply.mjs'
export {divide} from './divide.mjs'
export {sign} from './sign.mjs'
export {sqrt} from './sqrt.mjs'
export {subtract} from './subtract.mjs'

12
src/generic/multiply.mjs Normal file
View file

@ -0,0 +1,12 @@
export * from './Types/generic.mjs'
export const multiply = {
'undefined': () => u => u,
'undefined,...any': () => (u, rest) => u,
'any,undefined': () => (x, u) => u,
'any,undefined,...any': () => (x, u, rest) => u,
'any,any,undefined': () => (x, y, u) => u,
'any,any,undefined,...any': () => (x, y, u, rest) => u
// Bit of a hack since this should go on indefinitely...
}

3
src/generic/sqrt.mjs Normal file
View file

@ -0,0 +1,3 @@
export * from './Types/generic.mjs'
export const sqrt = {undefined: () => () => undefined}