Package org.jamesii.core.math.complex

Examples of org.jamesii.core.math.complex.Complex


    assertEquals(c.doubleValue(), c.getReal());
  }

  /** Tests the {@link Complex#floatValue()} method. */
  public void testFloatValue() {
    Complex c = new Complex(Math.random() * 100, Math.random() * 100);
    assertEquals(c.floatValue(), (float) c.getReal());
  }
View Full Code Here


    assertEquals(c.floatValue(), (float) c.getReal());
  }

  /** Tests the {@link Complex#intValue()} method. */
  public void testIntValue() {
    Complex c = new Complex(Math.random() * 100, Math.random() * 100);
    assertEquals(c.intValue(), (int) c.getReal());
  }
View Full Code Here

    assertEquals(c.intValue(), (int) c.getReal());
  }

  /** Tests the {@link Complex#longValue()} method. */
  public void testLongValue() {
    Complex c = new Complex(Math.random() * 100, Math.random() * 100);
    assertEquals(c.longValue(), (long) c.getReal());
  }
View Full Code Here

    assertEquals(c.longValue(), (long) c.getReal());
  }

  /** Tests the {@link Complex#byteValue()} method. */
  public void testByteValue() {
    Complex c = new Complex(Math.random() * 100, Math.random() * 100);
    assertEquals(c.byteValue(), (byte) c.getReal());
  }
View Full Code Here

    assertEquals(c.byteValue(), (byte) c.getReal());
  }

  /** Tests the {@link Complex#shortValue()} method. */
  public void testShortValue() {
    Complex c = new Complex(Math.random() * 100, Math.random() * 100);
    assertEquals(c.shortValue(), (short) c.getReal());
  }
View Full Code Here

  /**
   * Test abs.
   */
  public void testAbs() {
    // just for good measure -- getModulus is already tested elsewhere
    assertTrue(ComplexMath.abs(new Complex(12, 34)) == new Complex(12, 34)
        .getModulus());
  }
View Full Code Here

  /**
   * Test power real.
   */
  public void testPowerReal() {
    checkFields(ComplexMath.pow(new Complex(1, 2), 2), -3, 4, 5, 2.214297436);
    checkFields(ComplexMath.pow(new Complex(-1.5, 2.25), 2), -2.8125, -6.75,
        7.3125, -1.965587446);
    checkFields(ComplexMath.pow(new Complex(0, 1), 2), -1, 0, 1, PI);
    checkFields(ComplexMath.pow(new Complex(0, 1), 3), 0, -1, 1, -.5 * PI);
    checkFields(ComplexMath.pow(new Complex(0, 1), 4), 1, 0, 1, 0);
    checkFields(ComplexMath.pow(new Complex(1, 2), 4), -7, -24, 25,
        -1.854590436);
    checkFields(ComplexMath.pow(new Complex(-4.5, 3), 1.2), -7.557483862,
        .585242733, 7.580110249, 3.06430806);
  }
View Full Code Here

  /**
   * Test power complex.
   */
  public void testPowerComplex() {
    checkFields(ComplexMath.pow(new Complex(0, 1), new Complex(0, 1)),
        exp(-PI / 2), 0, exp(-PI / 2), 0);
    checkFields(ComplexMath.pow(new Complex(1, 1), new Complex(1, 1)),
        0.2739572538, 0.5837007588, sqrt(2) * exp(-PI / 4), .25 * PI + .5
            * log(2));
    // check whether power(double) as special case (with different computation)
    // yields the same results:
    Complex a = ComplexMath.pow(new Complex(1, 2), (4.5));
    Complex b = ComplexMath.pow(new Complex(1, 2), new Complex(4.5));
    checkFields(a, b.getReal(), b.getImaginary(), b.getModulus(),
        b.getArgument());
  }
View Full Code Here

   */
  public void testSqrt() {
    Complex[] x;

    // trivial case, square root of a positive real number
    x = ComplexMath.sqrt(new Complex(4, 0));
    assertTrue(x.length == 2);
    for (int i = 0; i < x.length; i++) {
      assertTrue(approximatelyEqual(x[i], new Complex(2, 0))
          || approximatelyEqual(x[i], new Complex(-2, 0)));
    }

    // square root of a negative real number
    x = ComplexMath.sqrt(new Complex(-9, 0));
    assertTrue(x.length == 2);
    for (int i = 0; i < x.length; i++) {
      assertTrue(approximatelyEqual(x[i], new Complex(0, 3))
          || approximatelyEqual(x[i], new Complex(0, -3)));
    }

    // square root of complex number
    x = ComplexMath.sqrt(new Complex(1, 2));
    assertTrue(x.length == 2);
    for (int i = 0; i < x.length; i++) {
      assertTrue(approximatelyEqual(x[i], new Complex(-1.2720196495140690,
          -0.7861513777574233))
          || approximatelyEqual(x[i], new Complex(1.2720196495140690,
              0.7861513777574233)));
    }
  }
View Full Code Here

   */
  public void testCbrt() {
    Complex[] x;

    // Trivial case, square root of a positive real number
    x = ComplexMath.cbrt(new Complex(8, 0));
    assertTrue(x.length == 3);
    for (int i = 0; i < x.length; i++) {
      assertTrue(approximatelyEqual(x[i], new Complex(-1, -1.7320508075688773))
          || approximatelyEqual(x[i], new Complex(-1, 1.7320508075688773))
          || approximatelyEqual(x[i], new Complex(2, 0)));
    }

    // Square root of a negative real number
    x = ComplexMath.cbrt(new Complex(-9, 0));
    assertTrue(x.length == 3);
    for (int i = 0; i < x.length; i++) {
      assertTrue(approximatelyEqual(x[i], new Complex(-2.0800838230519041, 0))
          || approximatelyEqual(x[i], new Complex(1.0400419115259521,
              -1.8014054327640041))
          || approximatelyEqual(x[i], new Complex(1.0400419115259521,
              1.8014054327640041)));
    }

    // Square root of complex number
    x = ComplexMath.cbrt(new Complex(8, -23));
    assertTrue(x.length == 3);
    for (int i = 0; i < x.length; i++) {
      assertTrue(approximatelyEqual(x[i], new Complex(-2.3332080247967582,
          -1.7197495217100161))
          || approximatelyEqual(x[i], new Complex(-0.3227427615486328,
              2.8804921826427131))
          || approximatelyEqual(x[i], new Complex(2.6559507863453910,
              -1.1607426609326970)));
    }
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.complex.Complex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.