2022-07-28 05:28:40 +00:00
|
|
|
import PocomathInstance from '../../core/PocomathInstance.mjs'
|
|
|
|
|
2022-07-19 18:54:22 +00:00
|
|
|
/* Use a plain object with keys re and im for a complex; note the components
|
|
|
|
* can be any type (for this proof-of-concept; in reality we'd want to
|
|
|
|
* insist on some numeric or scalar supertype).
|
|
|
|
*/
|
2022-07-25 18:56:12 +00:00
|
|
|
function isComplex(z) {
|
2022-07-19 18:54:22 +00:00
|
|
|
return z && typeof z === 'object' && 're' in z && 'im' in z
|
|
|
|
}
|
2022-07-19 16:52:16 +00:00
|
|
|
|
2022-07-28 05:28:40 +00:00
|
|
|
const Complex = new PocomathInstance('Complex')
|
|
|
|
Complex.installType('Complex', {
|
2022-07-25 18:56:12 +00:00
|
|
|
test: isComplex,
|
|
|
|
from: {
|
|
|
|
number: x => ({re: x, im: 0}),
|
|
|
|
bigint: x => ({re: x, im: 0n})
|
2022-07-22 20:49:14 +00:00
|
|
|
}
|
2022-07-28 05:28:40 +00:00
|
|
|
})
|
2022-07-19 16:52:16 +00:00
|
|
|
|
2022-07-28 05:28:40 +00:00
|
|
|
export {Complex}
|