picomath/complex/add.js
Glen Whitney 32bc9ca515 feat: Add complex numbers
With just the operations we have for numbers, and overall tests.
2022-03-25 01:54:20 -07:00

17 lines
506 B
JavaScript

import { anyComplex } from './complex.js'
export default function create(pmath) {
const complex = pmath('complex')
return pmath('add', [anyComplex, // naive, but this is just a P-o-C
(...addends) => {
let sum = complex(addends[0])
for (let i = 1; i < addends.length; ++i) {
const addend = complex(addends[i])
sum.re += addend.re
sum.im += addend.im
}
return sum
}])
}