public CalculateTimeOutput(TimeSpan?setupTime, TimeSpan?iterationTime, TimeSpan?runTime, string error, PrecisionMode precisionMode) { SetupTime = setupTime; IterationTime = iterationTime; RunTime = runTime; Error = error; PrecisionMode = precisionMode; }
public static HNumber Add(HNumber left, HNumber right, PrecisionMode precisionMode = PrecisionMode.UseHigher) { int precision = DEFAULT_PRECISION; if (precisionMode == PrecisionMode.UseHigher) { precision = Math.Max(left.Precision, right.Precision); } else if (precisionMode == PrecisionMode.UseLesser) { precision = Math.Min(left.Precision, right.Precision); } //TODO: ONLY WHEN SEMI ACCURATE RESULTS ARE REQUIRED int digitsTotal = left.DigitCount + right.DigitCount; left.Precision = digitsTotal; right.Precision = digitsTotal; left.Round(RoundingMode.PrecisionInt); right.Round(RoundingMode.PrecisionInt); if (left.Exponent < right.Exponent) { left.Truncate(left.DigitCount - (right.Exponent - left.Exponent)); } else if (left.Exponent > right.Exponent) { right.Truncate(right.DigitCount - (left.Exponent - right.Exponent)); } BigInteger mantissa = left.Mantissa + right.Mantissa; int exponent = Math.Max(left.Exponent, right.Exponent); if (precisionMode == PrecisionMode.KeepPrecision) { precision = CalculateDigitCount(mantissa); } HNumber result = new HNumber(mantissa, exponent, precision); return(result); }
public static HNumber Multiply(HNumber left, HNumber right, PrecisionMode precisionMode = PrecisionMode.UseHigher) { int precision = DEFAULT_PRECISION; if (precisionMode == PrecisionMode.UseHigher) { precision = Math.Max(left.Precision, right.Precision); } else if (precisionMode == PrecisionMode.UseLesser) { precision = Math.Min(left.Precision, right.Precision); } BigInteger mantissa = left.Mantissa * right.Mantissa; int exponent = left.Exponent + right.Exponent; if (precisionMode == PrecisionMode.KeepPrecision) { precision = CalculateDigitCount(mantissa); } HNumber result = new HNumber(mantissa, exponent, precision); return(result); }
public static HNumber Divide(HNumber left, HNumber right, PrecisionMode precisionMode = PrecisionMode.UseHigher) { int precision = DEFAULT_PRECISION; if (precisionMode == PrecisionMode.UseHigher) { precision = Math.Max(left.Precision, right.Precision); } else if (precisionMode == PrecisionMode.UseLesser) { precision = Math.Min(left.Precision, right.Precision); } if (right.IsZero) { throw new DivideByZeroException("The Divisor is zero"); } int digitDiff = left.Precision - (left.DigitCount - right.DigitCount); digitDiff = Math.Max(0, digitDiff); left.Mantissa *= BigInteger.Pow(10, digitDiff); left.Truncate(left.DigitCount + left.Exponent); BigInteger mantissa = BigInteger.Divide(left.Mantissa, right.Mantissa); int exponent = left.Exponent - right.Exponent - digitDiff; if (precisionMode == PrecisionMode.KeepPrecision) { precision = CalculateDigitCount(mantissa); } HNumber result = new HNumber(mantissa, exponent, precision); return(result); }