Exemplo n.º 1
0
        public void Polar()
        {
            Complex      cd1 = new Complex(1.1, -2.2);
            Complex      cd2 = new Complex(0, -2.2);
            Complex      cd3 = new Complex(1.1, 0);
            Complex      cd4 = new Complex(-1.1, 2.2);
            ComplexFloat cf1 = new ComplexFloat(1.1f, -2.2f);
            ComplexFloat cf2 = new ComplexFloat(0, -2.2f);
            ComplexFloat cf3 = new ComplexFloat(1.1f, 0);
            ComplexFloat cf4 = new ComplexFloat(-1.1f, 2.2f);

            Complex cdt = ComplexMath.Polar(cd1);

            Assert.AreEqual(cdt.Real, 2.460, TOLERENCE);
            Assert.AreEqual(cdt.Imag, -1.107, TOLERENCE);

            cdt = ComplexMath.Polar(cd2);
            Assert.AreEqual(cdt.Real, 2.2, TOLERENCE);
            Assert.AreEqual(cdt.Imag, -1.571, TOLERENCE);

            cdt = ComplexMath.Polar(cd3);
            Assert.AreEqual(cdt.Real, 1.1, TOLERENCE);
            Assert.AreEqual(cdt.Imag, 0, TOLERENCE);

            cdt = ComplexMath.Polar(cd4);
            Assert.AreEqual(cdt.Real, 2.460, TOLERENCE);
            Assert.AreEqual(cdt.Imag, 2.034, TOLERENCE);

            ComplexFloat cft = ComplexMath.Polar(cf1);

            Assert.AreEqual(cft.Real, 2.460, TOLERENCE);
            Assert.AreEqual(cft.Imag, -1.107, TOLERENCE);

            cft = ComplexMath.Polar(cf2);
            Assert.AreEqual(cft.Real, 2.2, TOLERENCE);
            Assert.AreEqual(cft.Imag, -1.571, TOLERENCE);

            cft = ComplexMath.Polar(cf3);
            Assert.AreEqual(cft.Real, 1.1, TOLERENCE);
            Assert.AreEqual(cft.Imag, 0, TOLERENCE);

            cft = ComplexMath.Polar(cf4);
            Assert.AreEqual(cft.Real, 2.460, TOLERENCE);
            Assert.AreEqual(cft.Imag, 2.034, TOLERENCE);
        }