2022-07-30 11:59:04 +00:00
|
|
|
import PocomathInstance from '../core/PocomathInstance.mjs'
|
|
|
|
import * as Complex from './Types/Complex.mjs'
|
|
|
|
import gcdType from '../generic/gcdType.mjs'
|
|
|
|
|
2022-08-06 15:27:44 +00:00
|
|
|
const gcdComplexRaw = {}
|
|
|
|
Object.assign(gcdComplexRaw, gcdType('Complex<bigint>'))
|
|
|
|
Object.assign(gcdComplexRaw, gcdType('Complex<NumInt>'))
|
2022-07-30 11:59:04 +00:00
|
|
|
const imps = {
|
2022-08-06 15:27:44 +00:00
|
|
|
gcdComplexRaw,
|
2022-07-30 11:59:04 +00:00
|
|
|
gcd: { // Only return gcds with positive real part
|
2022-08-06 15:27:44 +00:00
|
|
|
'Complex<T>,Complex<T>': ({
|
|
|
|
'gcdComplexRaw(Complex<T>,Complex<T>)': gcdRaw,
|
|
|
|
'sign(T)': sgn,
|
|
|
|
'one(T)': uno,
|
|
|
|
'negate(Complex<T>)': neg
|
2022-08-05 12:48:57 +00:00
|
|
|
}) => (z,m) => {
|
|
|
|
const raw = gcdRaw(z, m)
|
2022-08-06 15:27:44 +00:00
|
|
|
if (sgn(raw.re) === uno(raw.re)) return raw
|
2022-08-05 12:48:57 +00:00
|
|
|
return neg(raw)
|
2022-07-30 11:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const gcd = PocomathInstance.merge(Complex, imps)
|