feat: methods on Complex (#24)
All checks were successful
/ test (push) Successful in 17s

Adds all of the pocomath functions on Complex that do not depend on any unimplemented types or config properties, except quotient and roundquotient, where the design is murky. To get this working, adds some additional features:
  * Allows conversions to generic types, with the matched type
    determined from the return value of the built convertor
  * Adds predicate-based type patterns
  * Adds conversion from any non-complex type T to Complex(T)
  * Adds check for recursive loops in resolve (a key/signature depending on itself)

Reviewed-on: #24
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
Glen Whitney 2025-04-25 14:17:34 +00:00 committed by Glen Whitney
parent 0ff00ff8cb
commit aad62df8ac
33 changed files with 428 additions and 106 deletions

View file

@ -1,5 +1,6 @@
import assert from 'assert'
import math from '#nanomath'
import {NumberT} from '#number/NumberT.js'
describe('generic utility functions', () => {
it('tests whether an element is zero', () => {
@ -9,5 +10,16 @@ describe('generic utility functions', () => {
assert(isZero(false))
assert(!isZero(true))
assert(isZero(undefined))
assert(isZero(math.types.Complex(NumberT).zero))
assert(isZero(math.complex(-2e-16, 4e-17)))
assert(!isZero(math.complex(true)))
})
it('tests whether an element is real', () => {
const {isReal} = math
assert(isReal(Infinity))
assert(isReal(false))
assert(isReal(math.types.Complex(NumberT).one))
assert(isReal(math.complex(-3.25, 4e-16)))
assert(!isReal(math.complex(3, 4)))
})
})