Пример #1
0
        private static string GetRectangularFormat(Complex value, Calculator calc)
        {
            string result = string.Format(
                CultureInfo.CurrentCulture,
                "{3}{0}{2} {1}{4}",
                DoubleValue.Format(value.Real, calc),
                DoubleValue.Format(value.Imaginary, calc),
                Separator,
                StartDelimiter,
                EndDelimiter);

            return(result);
        }
Пример #2
0
        private static string GetPolarFormat(Complex value, Calculator calc)
        {
            string result = string.Format(
                CultureInfo.CurrentCulture,
                "{4}{0}{3} {1}{2}{5}",
                DoubleValue.Format(value.Magnitude, calc),
                PhasePrefix,
                DoubleValue.Format(calc.ConvertFromRadiansToAngle(value.Phase), calc),
                Separator,
                StartDelimiter,
                EndDelimiter);

            return(result);
        }
Пример #3
0
        private static string GetDecimalFormat(BigRational value, char separator, Calculator calc, out bool isDecimalFormat)
        {
            string result;

            // If converting from a fraction to a double overflows, we'll return the common format instead.
            double doubleValue = (double)value;

            if (double.IsInfinity(doubleValue) || double.IsNaN(doubleValue))
            {
                result          = GetCommonFormat(value, separator);
                isDecimalFormat = false;
            }
            else
            {
                result          = DoubleValue.Format(doubleValue, calc);
                isDecimalFormat = true;
            }

            return(result);
        }
Пример #4
0
        private static string GetAlgebraicFormat(Complex value, Calculator calc)
        {
            StringBuilder sb = new();

            if (value.Real == 0 && value.Imaginary != 0)
            {
                sb.Append(DoubleValue.Format(value.Imaginary, calc));
                sb.Append('i');
            }
            else
            {
                sb.Append(DoubleValue.Format(value.Real, calc));
                if (value.Imaginary != 0)
                {
                    sb.Append(Math.Sign(value.Imaginary) == -1 ? " - " : " + ");
                    sb.Append(DoubleValue.Format(Math.Abs(value.Imaginary), calc));
                    sb.Append('i');
                }
            }

            return(sb.ToString());
        }