feat: vector negate and subtract
This commit is contained in:
parent
cb3a93dd1c
commit
f398454d59
3 changed files with 15 additions and 1 deletions
|
@ -24,6 +24,12 @@ describe('Vector arithmetic functions', () => {
|
|||
assert.deepStrictEqual(
|
||||
add([[1, 2], [4, 2]], [0, -1]), [[1, 1], [4, 1]])
|
||||
})
|
||||
it('negates a vector', () => {
|
||||
assert.deepStrictEqual(math.negate([-3, 4, -5]), [3, -4, 5])
|
||||
})
|
||||
it('subtracts vectors', () => {
|
||||
assert.deepStrictEqual(math.subtract([-3, 4, -5], [8, 0, 2]), [-11, 4, -7])
|
||||
})
|
||||
it('computes the sum of a vector', () => {
|
||||
const sum = math.sum
|
||||
assert.strictEqual(sum([-3, 4, -5]), -4)
|
||||
|
|
|
@ -16,6 +16,9 @@ export const normsq = match(Vector, (math, V) => {
|
|||
export const abs = promoteUnary('abs')
|
||||
export const add = promoteBinary('add')
|
||||
|
||||
export const negate = promoteUnary('negate')
|
||||
export const subtract = promoteBinary('subtract')
|
||||
|
||||
export const sum = match(Vector, (math, V) => {
|
||||
const add = math.add.resolve([V.Component, V.Component])
|
||||
const haszero = math.haszero(V.Component)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue