From 1b8314c0ccf75a9e7208f1e5809f586b70677437 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Tue, 2 Aug 2022 09:52:39 -0700 Subject: [PATCH] refactor: Tighten definition of complex gcd to just GaussianInteger --- src/complex/gcd.mjs | 15 +++++++++------ src/complex/native.mjs | 2 -- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/complex/gcd.mjs b/src/complex/gcd.mjs index 84aa849..238d811 100644 --- a/src/complex/gcd.mjs +++ b/src/complex/gcd.mjs @@ -3,15 +3,18 @@ import * as Complex from './Types/Complex.mjs' import gcdType from '../generic/gcdType.mjs' const imps = { - gcdComplexRaw: gcdType('Complex'), + gcdGIRaw: gcdType('GaussianInteger'), 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) + '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) } } } export const gcd = PocomathInstance.merge(Complex, imps) - diff --git a/src/complex/native.mjs b/src/complex/native.mjs index 70d6b14..bea1db8 100644 --- a/src/complex/native.mjs +++ b/src/complex/native.mjs @@ -1,5 +1,3 @@ -import gcdType from '../generic/gcdType.mjs' - export * from './Types/Complex.mjs' export {abs} from './abs.mjs'