private void findSimplestForm() { if (Denominator == 1 || Numerator == 1) { _simplestForm = this; } else { BigIntPrime n = _num, d = _den; Boolean NMin = Numerator <= Denominator; if ((NMin?d:n).value % (NMin?n:d).value == 0) { if (NMin) { d /= n; n = 1; } else { n /= d; d = 1; } } else { int k = 0; while (Primes.pCache[k] <= (n | d)) { if (n.value % Primes.pCache[k] == 0 && d.value % Primes.pCache[k] == 0) { n /= Primes.pCache[k]; d /= Primes.pCache[k]; if (Primes.pCache[k] > maxPrime) { maxPrime = Primes.pCache[k]; } if ((NMin ? n : d).value == 1) { break; } } else { k++; if (k == Primes.pCache.Count) { break; } } } } if (d.value == Denominator) { _simplestForm = this; } else { _simplestForm = new Fraction(n, d); } } }
public Fraction(BigIntPrime n, BigIntPrime d) { _num = n; _den = d; }