pocomath/complex/Complex.mjs
Glen Whitney b82336e590 feat: Add complex numbers
No negation (and therefore no subtraction) since that needs self-reference.
2022-07-19 09:52:16 -07:00

15 lines
299 B
JavaScript

import typed from 'typed-function'
/* Use a plain object with keys re and im for a complex */
typed.addType({
name: 'Complex',
test: z => z && typeof z === 'object' && 're' in z && 'im' in z
})
typed.addConversion({
from: 'number',
to: 'Complex',
convert: x => ({re: x, im: 0})
})