private bool _IsTrivial(RawNum left, RawNum right) { OmgNum absLeft = new OmgNum(left); OmgNum absRight = new OmgNum(right); return(OmgOp.Less(absLeft, absRight)); }
internal RawNum Sqrt(RawNum left) { m_targetSquare = left; m_targetSquareNum = m_targetSquare.OmgWrapper(); m_rootAprox = OmgPool.GetRawZero(); m_buffer = OmgPool.GetRawZero(); _FillInitialApproximation(); while (!_AproxEqualToBuffer()) { var aproxCopy = OmgPool.GetRawZero(); aproxCopy.CopyFrom(m_rootAprox); var bufferCopy = OmgPool.GetRawZero(); bufferCopy.CopyFrom(m_buffer); _MakeGeronIteration(); if (OmgOp.Equal(aproxCopy.OmgWrapper(), m_buffer.OmgWrapper()) && OmgOp.Equal(bufferCopy.OmgWrapper(), m_rootAprox.OmgWrapper()) && OmgOp.Less(m_rootAprox.OmgWrapper(), m_buffer.OmgWrapper())) { break; } OmgPool.ReleaseNumber(bufferCopy); OmgPool.ReleaseNumber(aproxCopy); } OmgPool.ReleaseNumber(m_buffer); return(m_rootAprox); }
private bool _LeftAbsIsLess(OmgNum left, OmgNum right) { var absLeft = new OmgNum(left.Raw); var absRight = new OmgNum(right.Raw); return(OmgOp.Less(absLeft, absRight)); }
public void SetTestedNumber(OmgNum num) { m_tested?.Release(); m_tested = num; m_shurelyNotAPrime = OmgOp.Less(num, OmgNum.GetConst(2)); m_shurelyNotAPrime = m_shurelyNotAPrime || !m_smallPrimeTester.IsPrime(m_tested); if (!m_shurelyNotAPrime && OmgOp.Greater(num, OmgNum.GetConst(1))) { _FactorPowerOfTwo(num); } }
public bool IsPrimeToBase(OmgNum testBase) { if (OmgOp.Less(m_tested, OmgNum.GetConst(1))) { return(false); } if (m_shurelyNotAPrime) { return(false); } bool result = _MakeTest(testBase); return(result); }
public bool IsPrime(OmgNum tested) { foreach (var prime in s_smallPrimes) { if (OmgOp.Less(tested, prime) || OmgOp.Equal(tested, prime)) { return(true); } var mod = OmgOp.Mod(tested, prime); bool isComposite = mod.IsZero(); mod.Release(); if (isComposite) { return(false); } } return(true); }