本文整理汇总了C#中Complex.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Complex.ToString方法的具体用法?C# Complex.ToString怎么用?C# Complex.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Complex
的用法示例。
在下文中一共展示了Complex.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyToString
private static void VerifyToString(Complex complex)
{
double real = complex.Real;
double imaginary = complex.Imaginary;
string expected;
string actual;
expected = "(" + real.ToString() + ", " + imaginary.ToString() + ")";
actual = complex.ToString();
Assert.Equal(expected, actual);
CultureInfo germanCultureInfo = new CultureInfo("de-DE");
NumberFormatInfo germanNumberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
expected = "(" + real.ToString(germanNumberFormatInfo) + ", " + imaginary.ToString(germanNumberFormatInfo) + ")";
actual = complex.ToString(germanNumberFormatInfo);
Assert.Equal(expected, actual);
foreach (string format in Support.supportedStdNumericFormats)
{
expected = "(" + real.ToString(format) + ", " + imaginary.ToString(format) + ")";
actual = complex.ToString(format);
Assert.True(expected.Equals(actual), string.Format("ToString() failed for format {0}.\n\tExpected: <{1}>\n\tActual: <{2}>", format, actual, expected));
germanNumberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
expected = "(" + real.ToString(format, germanNumberFormatInfo) + ", " + imaginary.ToString(format, germanNumberFormatInfo) + ")";
actual = complex.ToString(format, germanNumberFormatInfo);
Assert.True(expected.Equals(actual), string.Format("ToString() failed for format {0} in de-DE.\n\tExpected: <{1}>\n\tActual: <{2}>", format, actual, expected));
}
}
示例2: VerifyToString
private static void VerifyToString(Complex complex)
{
Double real = complex.Real;
Double imaginary = complex.Imaginary;
String manual;
String automatic;
manual = "(" + real.ToString() + ", " + imaginary.ToString() + ")";
automatic = complex.ToString();
if (!automatic.Equals(manual))
{
Console.WriteLine("Error-str2F3P4001! automatic:{0} does not equal to manual:{1}", automatic, manual);
Assert.True(false, "Verification Failed");
}
CultureInfo germanCultureInfo = new CultureInfo("de-DE");
NumberFormatInfo germanNumberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
manual = "(" + real.ToString(germanNumberFormatInfo) + ", " + imaginary.ToString(germanNumberFormatInfo) + ")";
automatic = complex.ToString(germanNumberFormatInfo);
if (!automatic.Equals(manual))
{
Console.WriteLine("Error-str2F3P4+NFI! automatic:{0} does not equal to manual:{1}", automatic, manual);
Assert.True(false, "Verification Failed");
}
foreach (String format in Support.supportedStdNumericFormats)
{
manual = "(" + real.ToString(format) + ", " + imaginary.ToString(format) + ")";
automatic = complex.ToString(format);
if (!automatic.Equals(manual))
{
Console.WriteLine("Error-str2F3P4+FMT-{0}! automatic:{1} does not equal to manual:{2}", format, automatic, manual);
Assert.True(false, "Verification Failed");
}
germanNumberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
manual = "(" + real.ToString(format, germanNumberFormatInfo) + ", " + imaginary.ToString(format, germanNumberFormatInfo) + ")";
automatic = complex.ToString(format, germanNumberFormatInfo);
if (!automatic.Equals(manual))
{
Console.WriteLine("Error-str2F3P4+FMT-{0}+{1}! automatic:{2} does not equal to manual:{3}", format, "de-DE", automatic, manual);
Assert.True(false, "Verification Failed");
}
}
}
示例3: Main
static void Main(string[] args)
{
Complex z = new Complex();
z.real = 4;
z.imaginar = 3;
z.CalculateAbsoluteValue();
// ... or:
/*
Complex z = new Complex
{
real = 4,
imaginar = 3
};
z.CalculateAbsoluteValue();
*/
Console.WriteLine("\n\n---===Struct===---\n");
Console.WriteLine(z.ToString());
Console.WriteLine("Modulul: {0}", z.modul);
Console.ReadKey();
Complex z2 = new Complex(5, 3);
z2.CalculateAbsoluteValue();
Console.WriteLine("\n\n---===Struct===---\n");
Console.WriteLine(z2.ToString());
Console.WriteLine("Modulul: {0}", z2.modul);
Console.ReadKey();
}
示例4: addOpperand
public override void addOpperand(Calc calc, Complex c)
{
//calc.CurrentState = ErrorState.Singleton;
//throw new Exception("Cannot add opperand in opperand entered state");
calc.setDisplay(c.ToString());
calc.CurrentState = OpperandEnteredState.Singleton;
}
示例5: addOpperand
public override void addOpperand(Calc calc, Complex c)
{
//just replace current w/ this
calc.setDisplay(c.ToString());
calc.CurrentState = OpperandEnteredState.Singleton;
}
示例6: addOpperand
public override void addOpperand(Calc calc, Complex c)
{
//calc.Opperand1=calc.Total;
//calc.Opperand2=c;
calc.setDisplay(c.ToString());
// Complex result = calc.pending_op.compute(calc.Total, calc.Opperand2);
// calc.Total=result;
// calc.Opperand1=result;
//why did I do this???
//calc.pending_op=null;
calc.CurrentState=OpperandEnteredState.Singleton;
//calc.CurrentState=CompState.Singleton;
}
示例7: Main
static void Main(string[] args)
{
Complex c1 = new Complex();
c1.Real = 250;
c1.Imaginary = 10;
Complex c2 = new Complex(75, 20);
Complex c3 = c1.Add(c2);
Console.WriteLine(c1.ToString());
Console.WriteLine(c2.ToString());
Console.WriteLine(c3.ToString());
Console.ReadKey();
}
示例8: ToString
public static void ToString(double real, double imaginary)
{
var complex = new Complex(real, imaginary);
string expected = "(" + real.ToString() + ", " + imaginary.ToString() + ")";
string actual = complex.ToString();
Assert.Equal(expected, actual);
NumberFormatInfo numberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
expected = "(" + real.ToString(numberFormatInfo) + ", " + imaginary.ToString(numberFormatInfo) + ")";
actual = complex.ToString(numberFormatInfo);
Assert.Equal(expected, complex.ToString(numberFormatInfo));
foreach (string format in s_supportedStandardNumericFormats)
{
expected = "(" + real.ToString(format) + ", " + imaginary.ToString(format) + ")";
actual = complex.ToString(format);
Assert.Equal(expected, actual);
expected = "(" + real.ToString(format, numberFormatInfo) + ", " + imaginary.ToString(format, numberFormatInfo) + ")";
actual = complex.ToString(format, numberFormatInfo);
Assert.Equal(expected, actual);
}
}
示例9: Main
static void Main(string[] args)
{
TwoDimVector A = new TwoDimVector("A", new TwoDimPoint(0, 0), new TwoDimPoint(2, 2));
TwoDimVector B = new TwoDimVector("B", new TwoDimPoint(0, 0), new TwoDimPoint(1, 1));
TwoDimVector C = A + B;
C.Name = "C";
TwoDimVector D = A - B;
D.Name = "D";
TwoDimVector E = A * 2;
E.Name = "E";
TwoDimVector F = A / 2;
F.Name = "F";
Complex ComplexA = new Complex(1, -2);
Complex ComplexB = new Complex(-3, 4);
Complex ComplexC = ComplexA + ComplexB;
Complex ComplexD = ComplexA - ComplexB;
Complex ComplexE = ComplexA * ComplexB;
Console.WriteLine("--------------------");
Console.WriteLine("Vector's part.\n");
Console.WriteLine(A.GetFullDescription());
Console.Write(Environment.NewLine);
Console.WriteLine(B.GetFullDescription());
Console.Write(Environment.NewLine);
Console.WriteLine("\nC = A + B");
Console.WriteLine(C.GetFullDescription());
Console.Write(Environment.NewLine);
Console.WriteLine("\nD = A - B");
Console.WriteLine(D.GetFullDescription());
Console.Write(Environment.NewLine);
Console.WriteLine("\nE = A * 2");
Console.WriteLine(E.GetFullDescription());
Console.Write(Environment.NewLine);
Console.WriteLine("\nF = A / 2");
Console.WriteLine(F.GetFullDescription());
Console.Write(Environment.NewLine);
Console.WriteLine("--------------------");
Console.WriteLine("Complex's part.\n");
Console.WriteLine(string.Format("Complex A = {0}", ComplexA.ToString()));
Console.Write(Environment.NewLine);
Console.WriteLine(string.Format("Complex B = {0}", ComplexB.ToString()));
Console.Write(Environment.NewLine);
Console.WriteLine("Complex C = A + B");
Console.WriteLine(string.Format("Complex C = {0}", ComplexC.ToString()));
Console.Write(Environment.NewLine);
Console.WriteLine("Complex D = A - B");
Console.WriteLine(string.Format("Complex D = {0}", ComplexD.ToString()));
Console.Write(Environment.NewLine);
Console.WriteLine("Complex E = A * B");
Console.WriteLine(string.Format("Complex E = {0}", ComplexE.ToString()));
Console.Write(Environment.NewLine);
Console.ReadLine();
}
示例10: Add
public string Add(ref Complex x, ref Complex y, out Complex rsl)
{
rsl = new Complex(x.Real + y.Real, x.Imaginary + y.Imaginary);
return rsl.ToString();
}
示例11: JuliaSearcher_Load
private void JuliaSearcher_Load(object sender, EventArgs e)
{
fpb1 = new FractalPictureBox();
fpb1.SizeMode = PictureBoxSizeMode.AutoSize;
fpb1.ContextMenuStrip = contextMenuStrip1;
if(_m_fcm==null)_m_fcm = new Simple2DFractalColorMode();
panel1.Controls.Add(fpb1);
fpb1.ToClickMode();
if(_mandelbrot==null)_mandelbrot = new Mandelbrot();
_m_fap = _mandelbrot.CreateFractal(panel1.Width, panel1.Height);
fpb1.Image = _m_fcm.GetDrawnBitmap(_m_fap);
fpb1.MouseMove += (_sender, _e) => {label1.Text = _get_complex_loc(_mandelbrot,_e.X,_e.Y).ToString(); };
fpb2 = new FractalPictureBox();
fpb2.SizeMode = PictureBoxSizeMode.AutoSize;
panel2.Controls.Add(fpb2);
fpb1.MouseDown += (_sender, _e) =>
{
if (!clickable) return;
if (_e.Button != MouseButtons.Left) return;
_using_complex = _get_complex_loc(_mandelbrot, _e.X, _e.Y);
label2.Text=_using_complex.ToString();
_julia.SetComplex(_using_complex);
fpb2.Image = _j_fcm.GetDrawnBitmap(((_2DFractal)_julia).CreateFractal(panel2.Width, panel2.Height));
};
fpb2.RectangleSelected += (_sender, rec) =>
{
((_2DFractal)_julia).CreateParallelFractal(panel2.Width, panel2.Height, rec.X, rec.Y, rec.Width, rec.Height, true);
};
((_2DFractal)_julia).ParallelFractalCreatingFinished += (s, fap) =>
{
Action<Bitmap> act=(bmp)=>{fpb2.Image=bmp;};
Invoke(act, _j_fcm.GetDrawnBitmap(fap));
};
fpb2.SelectionPen = null;
fpb1.RectangleSelected += (_s, rec) => {
_mandelbrot.CreateParallelFractal(panel1.Width, panel1.Height, rec.X, rec.Y, rec.Width, rec.Height,true);
};
_mandelbrot.ParallelFractalCreatingFinished += (s, fap) =>
{
Action<Bitmap> act = (bmp) => { fpb1.Image = bmp; };
Invoke(act, _m_fcm.GetDrawnBitmap(fap));
};
fpb2.ContextMenuStrip = contextMenuStrip2;
fpb1.SelectionPen = null;
clickable = true;
_fpb1_h_scale = this.Width / (double)panel1.Width;
_fpb1_v_scale = this.Height / (double)panel1.Height;
_fpb2_h_scale = this.Width / (double)panel2.Width;
_fpb2_v_scale = this.Height / (double)panel2.Height;
oldheight = panel1.Height;
oldwidth = panel1.Width;
вРежимВращенияToolStripMenuItem.Visible = вРежимВращенияToolStripMenuItem.Enabled = _mandelbrot is IUsingQuaternion;
}
示例12: TestCase
public void TestCase()
{
Calc c=new Calc();
Assert.True(c.CurrentState is StartState);
c.enterOperand("3 4");
Assert.True(c.CurrentState is OpperandEnteredState);
Assert.AreEqual(c.Total, new Complex(0,0));
Assert.AreEqual(new Complex(3,4), c.Opperand2);
//should fail b/c there's no operator to use!
c.compute();
Assert.IsTrue(c.CurrentState is ErrorState);
//add operator
c.enterOp("+");
c.compute();
Complex answer=new Complex(3,4);
Assert.IsTrue(c.CurrentState is CompState);
Assert.AreEqual(answer, c.Total);
Assert.AreEqual(answer, c.Opperand1);
//now let's subtract and check if we get 0+0i
c.enterOperand("3 4");
c.enterOp("-");
c.compute();
answer=new Complex(0,0);
Assert.IsTrue(c.CurrentState is CompState);
Assert.AreEqual(answer, c.Total);
Assert.AreEqual(answer, c.Opperand1);
//now lets add 5-6i
Complex old_lhs=c.Opperand1;
c.enterOp("+");
Assert.IsTrue(c.CurrentState is OpperatorEntredState);
c.enterOperand("5 -6");
Assert.AreEqual(new Complex(5,-6), c.Opperand2);
c.compute();
answer=new Complex(5,-6);
Assert.IsTrue(c.CurrentState is CompState);
Assert.AreEqual(answer.ToString(), c.Total.ToString());
Assert.AreEqual(old_lhs.ToString(), c.Opperand1.ToString());
//test multplication (5-6i) * (2+3i) = (28+3i)
c.enterOp("*");
Assert.AreEqual(c.Total.ToString(), c.Opperand1.ToString());
c.enterOperand("2 3");
c.compute();
answer=new Complex(28,3);
Assert.IsTrue(c.CurrentState is CompState);
Assert.AreEqual(answer.ToString(), c.Total.ToString());
//test division (28+3i) / (3-2i)=(6+5i)
c.enterOp("/");
c.enterOperand("3 -2");
c.compute();
answer=new Complex(6,5);
Assert.IsTrue(c.CurrentState is CompState);
Assert.AreEqual(answer.ToString(), c.Total.ToString());
//test error handling
Complex opp1=c.Opperand1;
Complex opp2=c.Opperand2;
c.enterOperand("3");
Assert.IsTrue(c.CurrentState is ErrorState);
//ensure no opperands are changed
Assert.AreEqual(opp1, c.Opperand1);
Assert.AreEqual(opp2, c.Opperand2);
Assert.AreEqual(answer.ToString(), c.Total.ToString()); //ensure previous sum remains
//enter bad input again!
c.enterOperand("3 3 3 3 3");
Assert.IsTrue(c.CurrentState is ErrorState);
//ensure no opperands are changed
Assert.AreEqual(opp1, c.Opperand1);
Assert.AreEqual(opp2, c.Opperand2);
Assert.AreEqual(answer.ToString(), c.Total.ToString()); //ensure previous sum remains
//test bad operatOR inputs
IBinOp old_op=c.pending_op;
c.enterOp("a");
Assert.IsTrue(c.CurrentState is ErrorState);
//ensure no opperands are changed
Assert.AreEqual(opp1, c.Opperand1);
Assert.AreEqual(opp2, c.Opperand2);
Assert.AreEqual(old_op, c.pending_op);
Assert.AreEqual(answer.ToString(), c.Total.ToString()); //ensure previous sum remains
//check that op1 and op2 and opp are same from before errors started
Assert.AreEqual(opp1, c.Opperand1);
Assert.AreEqual(opp2, c.Opperand2);
Assert.AreEqual(old_op, c.pending_op);
c.enterOp("+");
c.enterOperand("6 6");
c.compute();
answer=new Complex(12,11);
Assert.IsTrue(c.CurrentState is CompState);
Assert.AreEqual(answer.ToString(), c.Total.ToString());
//reset calc
//.........这里部分代码省略.........
示例13: Set
/// <summary>
/// Sets the complex value of a variant.
/// </summary>
/// <param name="complexValue">Complex value to set</param>
public void Set(Complex complexValue)
{
_value = complexValue.Real;
_intValue = (int)complexValue.Real;
_boolValue = ((int)complexValue.Real != 0);
_strValue = complexValue.ToString();
_complexValue = complexValue;
Type = SymType.COMPLEX;
HasValue = true;
}
示例14: NumberToken
public NumberToken(Complex val)
{
this.TokenString = val.ToString();
this.TokenNumValue = val;
}
示例15: OperatorOverloading
public static void OperatorOverloading()
{
Console.WriteLine("\nOVERLOADING and OVERRIDING");
Complex x = new Complex(3, 2);
Complex y = x;
Console.WriteLine("x = " + x.ToString()); // ToString() override
Console.WriteLine("y = " + y.ToString()); // Without overide it displays
Console.WriteLine("Changing y..."); // All classes are reference types
y.Real = 9;
Console.WriteLine("x = " + x.ToString());
Console.WriteLine("y = " + y.ToString());
Complex z = x + y;
Console.WriteLine("z = " + z.ToString());
}