feat: Start adding vector arithmetic
So far, abs, add, norm, normsq, and sum are supported. To get them to work, also implements the following: * refactor: Use ReturnType function rather than just accessing .returns * feat: distinguish marking a function as a behavior from its return type * refactor: Rename `NotAType` to `Unknown` because it must be made closer to a bona fide type for the sake of inhomogeneous vectors * feat: make resolving a TypeDispatcher method on a type vector including `Unknown` into a no-op; that simplifies a number of generic behaviors * feat: add `haszero` method parallel to `hasnan` * feat: track the Vector nesting depth of Vector specializations
This commit is contained in:
parent
ec97b0e20a
commit
cb3a93dd1c
26 changed files with 238 additions and 171 deletions
|
@ -1,6 +1,6 @@
|
|||
import assert from 'assert'
|
||||
import math from '#nanomath'
|
||||
import {ReturnTyping} from '#core/Type.js'
|
||||
import {ReturnType, ReturnTyping} from '#core/Type.js'
|
||||
|
||||
const {Complex, NumberT} = math.types
|
||||
|
||||
|
@ -8,7 +8,7 @@ describe('generic arithmetic', () => {
|
|||
it('squares anything', () => {
|
||||
const sq = math.square
|
||||
assert.strictEqual(sq(7), 49)
|
||||
assert.strictEqual(math.square.resolve([NumberT]).returns, NumberT)
|
||||
assert.strictEqual(ReturnType(math.square.resolve([NumberT])), NumberT)
|
||||
assert.deepStrictEqual(sq(math.complex(3, 4)), math.complex(-7, 24))
|
||||
const eyes = math.complex(0, 2)
|
||||
assert.strictEqual(sq(eyes), -4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue