chore: Remove complex 'base cases' that are no longer needed

This commit is contained in:
Glen Whitney 2022-07-22 13:40:40 -07:00
parent 6e7f244c33
commit cf8ad1edfc
2 changed files with 4 additions and 13 deletions

View File

@ -1,16 +1,10 @@
import {Types, numComplex} from './Types/Complex.mjs'
export {Types} from './Types/Complex.mjs'
export {Types}
export const add = {
'...Complex': [['self'], ref => addends => {
if (addends.length === 0) return {re:0, im:0}
const seed = addends.shift()
return addends.reduce((w,z) => {
/* Need a "base case" to avoid infinite self-reference loops */
if (numComplex(z) && numComplex(w)) {
return {re: w.re + z.re, im: w.im + z.im}
}
return {re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)}
}, seed)
return addends.reduce((w,z) =>
({re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)}), seed)
}]
}

View File

@ -1,10 +1,7 @@
import {Types, numComplex} from './Types/Complex.mjs'
export {Types} from './Types/Complex.mjs'
export {Types}
export const negate = {
Complex: [['self'], ref => z => {
/* need a "base case" to avoid infinite self-reference */
if (numComplex(z)) return {re: -z.re, im: -z.im}
return {re: ref.self(z.re), im: ref.self(z.im)}
}]
}