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'
|
|
|
|
|
|
|
|
const imps = {
|
2022-08-05 12:48:57 +00:00
|
|
|
gcdGIRaw: gcdType('GaussianInteger'),
|
2022-07-30 11:59:04 +00:00
|
|
|
gcd: { // Only return gcds with positive real part
|
2022-08-05 12:48:57 +00:00
|
|
|
'GaussianInteger,GaussianInteger': ({
|
|
|
|
'gcdGIRaw(GaussianInteger,GaussianInteger)': gcdRaw,
|
|
|
|
'sign(bigint)': sgn,
|
|
|
|
'negate(GaussianInteger)': neg
|
|
|
|
}) => (z,m) => {
|
|
|
|
const raw = gcdRaw(z, m)
|
|
|
|
if (sgn(raw.re) === 1n) return raw
|
|
|
|
return neg(raw)
|
2022-07-30 11:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const gcd = PocomathInstance.merge(Complex, imps)
|