public virtual object FormatLabel(string format, object data, int?decimals = null) { if ((this.EnableTitle || this.EnableLabelFormat) && this.ActualDisplayUnit != null) { double num1 = this.Project(Convert.ToDouble(data, (IFormatProvider)CultureInfo.CurrentCulture)); double num2; if (decimals.HasValue) { num2 = Math.Round(num1, decimals.Value); } else { double precision = Math.Max(DoubleHelper.GetPrecision(num1), 1E-308); num2 = DoubleHelper.RoundWithPrecision(num1, precision); } data = (object)num2; format = !this.EnableLabelFormat || string.IsNullOrEmpty(this.ActualDisplayUnit.LabelFormat) ? "{0}" : this.ActualDisplayUnit.LabelFormat; } else { format = this.RemoveFractionIfNecessary(format); format = ValueHelper.PrepareFormatString(format); } format = this.ReplaceDFormat(format); return((object)string.Format((IFormatProvider)CultureInfo.CurrentCulture, format, new object[1] { data })); }
public static double GetMinimumDelta(IList <double> sortedValues) { double num1 = 0.0; if (sortedValues != null && sortedValues.Count > 1) { double num2 = 0.0; double precision = DoubleHelper.GetPrecision(new double[2] { sortedValues[0], sortedValues[sortedValues.Count - 1] }); for (int index = 0; index < sortedValues.Count; ++index) { double num3 = sortedValues[index]; if (index > 0) { double num4 = Math.Abs(num3 - num2); if (DoubleHelper.GreaterWithPrecision(num4, 0.0, precision) && (num4 < num1 || num1 == 0.0)) { num1 = num4; } } num2 = num3; } } return(num1); }
public static IEnumerable <double> GetSteps(this double from, double to, int count) { if (count > 0) { double step = (to - from) / (double)count; double precision = DoubleHelper.GetPrecision(new double[2] { from, to }); double x = from; while (!DoubleHelper.EqualsWithPrecision(x, to, precision)) { if (x >= to) { yield break; } else { yield return(x); x += step; } } yield return(to); } }
public static IEnumerable <double> GetSteps(this double from, double to, double step) { double precision = DoubleHelper.GetPrecision(new double[2] { from, to }); if (DoubleHelper.EqualsWithPrecision(step, 0.0, precision)) { throw new ArgumentOutOfRangeException("step", string.Format("The step={0} is negligebly small for the range of {1} to {2}", (object)step, (object)from, (object)to)); } double x = from; while (!DoubleHelper.EqualsWithPrecision(x, to, precision)) { if (x >= to) { yield break; } else { yield return(x); x += step; } } yield return(to); }
public virtual bool IsApplicableTo(double value) { value = Math.Abs(value); double precision = DoubleHelper.GetPrecision(3, value); if (DoubleHelper.GreaterOrEqualWithPrecision(value, this.ApplicableRangeMinimum, precision)) { return(DoubleHelper.LessWithPrecision(value, this.ApplicableRangeMaximum, precision)); } return(false); }
public static double GetPrecision(params double[] values) { return(DoubleHelper.GetPrecision(12, values)); }