fix: Separate typed instance for each PocomathInstance #15
@ -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)
|
||||
}]
|
||||
}
|
||||
|
@ -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)}
|
||||
}]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user