public void Set(CRatio thatRatio) { _numerator = thatRatio.Numerator; _denominator = thatRatio.Denominator; _isValid = thatRatio.IsValid; Normalize(); }
public void ApplyMultiplication(CRatio thatRatio) { // Ignore overflow cases because they will not come up in this application. _numerator *= thatRatio.Numerator; _denominator *= thatRatio.Denominator; NormalizeSign(); }
// Apply power to the extent that it works out to an integer ratio. // This CRatio is always an integer, so the denominator is always 1 in this application. // Return true if it works out evenly (set ratioPower = 1/1) // else return false and set ratioPower to the unapplied portion. // Ignore overflow cases because they will not come up in this application. public bool ApplyPower(ref CRatio ratioPower) { bool bSuccess = false; ratioPower.NormalizeSign(); if (this._numerator > 256 || ratioPower.Numerator > 16) { // Avoid overflow bSuccess = false; } if (ratioPower.Numerator == 0) { Set(1); bSuccess = true; } else if (ratioPower.Numerator > 0) { bSuccess = false; // Apply power numerator int intOrigNumerator = _numerator; for (int intPower = ratioPower.Numerator - 1; intPower > 0; --intPower) { bSuccess = true; _numerator *= intOrigNumerator; } ratioPower.SetNumerator(1); // Apply power denominator. if (ratioPower.Denominator != 1) { if (_numerator == 1) { bSuccess = true; ratioPower.Set(1); } else { // calculate root CPrimeFactorList thisPrimeFactorList = new CPrimeFactorList(_numerator); bSuccess = thisPrimeFactorList.ApplyRoot(ratioPower.Denominator); if (bSuccess) { _numerator = thisPrimeFactorList.Value; ratioPower.Set(1); // power = 1/1 } } } } else // negative numerator { bSuccess = false; } return(bSuccess); }
public CRatio(CRatio thatRatio) { _numerator = thatRatio.Numerator; _denominator = thatRatio.Denominator; Normalize(); }
public bool Equals(CRatio thatRatio) { return(this._numerator == thatRatio._numerator && this._denominator == thatRatio._denominator); }
public void ApplyDivision(CRatio thatRatio) { CRatio ratioDivision = new CRatio(thatRatio.Denominator, thatRatio.Numerator); ApplyMultiplication(ratioDivision); }