Glen Whitney
c429c19dfe
This should eventually be moved into typed-function itself, but for now it can be implemented on top of the existing typed-function. Uses subtypes to define (and error-check) gcd and lcm, which are only defined for integer arguments. Resolves #36.
18 lines
534 B
JavaScript
18 lines
534 B
JavaScript
import PocomathInstance from '../core/PocomathInstance.mjs'
|
|
import * as Complex from './Types/Complex.mjs'
|
|
import gcdType from '../generic/gcdType.mjs'
|
|
|
|
const imps = {
|
|
gcdComplexRaw: gcdType('Complex'),
|
|
gcd: { // Only return gcds with positive real part
|
|
'Complex, Complex': ({gcdComplexRaw, sign, one, negate}) => (z,m) => {
|
|
const raw = gcdComplexRaw(z, m)
|
|
if (sign(raw.re) === one(raw.re)) return raw
|
|
return negate(raw)
|
|
}
|
|
}
|
|
}
|
|
|
|
export const gcd = PocomathInstance.merge(Complex, imps)
|
|
|