示例#1
0
  public void testScalarMultiplyInf() {
    Complex z = new Complex(1, 1);
    Complex w = z.multiply(Double.POSITIVE_INFINITY);
    assertEquals(w.getReal(), inf, 0);
    assertEquals(w.getImaginary(), inf, 0);

    w = z.multiply(Double.NEGATIVE_INFINITY);
    assertEquals(w.getReal(), inf, 0);
    assertEquals(w.getImaginary(), inf, 0);
  }
示例#2
0
 public void testScalarMultiply() {
   Complex x = new Complex(3.0, 4.0);
   double y = 2.0;
   Complex z = x.multiply(y);
   assertEquals(6.0, z.getReal(), 1.0e-5);
   assertEquals(8.0, z.getImaginary(), 1.0e-5);
 }
示例#3
0
 public void testMultiply() {
   Complex x = new Complex(3.0, 4.0);
   Complex y = new Complex(5.0, 6.0);
   Complex z = x.multiply(y);
   assertEquals(-9.0, z.getReal(), 1.0e-5);
   assertEquals(38.0, z.getImaginary(), 1.0e-5);
 }
示例#4
0
  public void testMultiplyNaNInf() {
    Complex z = new Complex(1, 1);
    Complex w = z.multiply(infOne);
    assertEquals(w.getReal(), inf, 0);
    assertEquals(w.getImaginary(), inf, 0);

    // [MATH-164]
    assertTrue(new Complex(1, 0).multiply(infInf).equals(Complex.INF));
    assertTrue(new Complex(-1, 0).multiply(infInf).equals(Complex.INF));
    assertTrue(new Complex(1, 0).multiply(negInfZero).equals(Complex.INF));

    w = oneInf.multiply(oneNegInf);
    assertEquals(w.getReal(), inf, 0);
    assertEquals(w.getImaginary(), inf, 0);

    w = negInfNegInf.multiply(oneNaN);
    assertTrue(Double.isNaN(w.getReal()));
    assertTrue(Double.isNaN(w.getImaginary()));
  }
  public static void testArithmetic() {
    Complex c1 = new Complex(1, 2);
    Complex c2 = new Complex(1, 3);

    Complex sum = c1.add(c2);
    System.out.println("(" + c1 + ")" + " + " + "(" + c2 + ")" + " = " + sum);

    Complex product = c1.multiply(c2);
    System.out.println("(" + c1 + ")" + " * " + "(" + c2 + ")" + " = " + product);

    Complex product2 = c1.multiply(2);
    System.out.println("(" + c1 + ")" + " * " + "2" + " = " + product2);

    // show step to get abs value
    // + c1.getReal() + "^2 " + "+" + c1.getComplex() + "^2" + " = "
    System.out.println("Absolute value of " + "(" + c1 + ")" + " = " + c1.abs());

    System.out.println();
  }
示例#6
0
 public void testScalarMultiplyNaN() {
   Complex x = new Complex(3.0, 4.0);
   Complex z = x.multiply(Double.NaN);
   assertTrue(z.isNaN());
 }
示例#7
0
 public void testMultiplyNaN() {
   Complex x = new Complex(3.0, 4.0);
   Complex z = x.multiply(Complex.NaN);
   assertTrue(z.isNaN());
 }