github.com/neugram/ng@v0.0.0-20180309130942-d472ff93d872/eval/testdata/complex.ng (about)

     1  complex(1, 2)
     2  complex(1, 2.2)
     3  complex(1, float32(2))
     4  complex(1, float64(2))
     5  
     6  complex(1.1, 2)
     7  complex(1.1, 2.2)
     8  complex(1.1, float32(2))
     9  complex(1.1, float64(2))
    10  
    11  complex(float32(2), float32(3)) + complex64(2)
    12  
    13  complex(float64(2), float64(3)) + complex128(0)
    14  
    15  complex128(0) + complex128(2.2) + complex128(complex64(3.5)+complex64(3))
    16  complex128(1) + 1
    17  complex64(1) + 1
    18  
    19  (complex128(0) + complex128(3.3)) + complex(1, 2)
    20  
    21  // TODO: c := 2*(complex128(2) + complex(1,2)) + 1
    22  // TODO: c := complex(1,2) + complex64(2)
    23  
    24  real(1 + 2i)
    25  real(1 + 2i) + 2
    26  real(1 + 2i) + 2.2
    27  // TODO: real(1 + 2i) + float32(2.2)
    28  real(1 + 2i) + float64(2.2)
    29  
    30  real(complex64(1)) + 1
    31  real(complex64(1)) + 1.1
    32  real(complex64(1)) + float32(1)
    33  
    34  imag(1 + 2i)
    35  imag(1 + 2i) + 2
    36  imag(1 + 2i) + 2.2
    37  // TODO: imag(1 + 2i) + float32(2.2)
    38  imag(1 + 2i) + float64(2.2)
    39  
    40  imag(complex64(1)) + 1
    41  imag(complex64(1)) + 1.1
    42  imag(complex64(1)) + float32(1)
    43  
    44  
    45  if real(1 + 2i) != 1.0 {
    46  	panic("ERROR")
    47  }
    48  
    49  if imag(1 + 2i) != 2.0 {
    50  	panic("ERROR")
    51  }
    52  
    53  c := complex(1, 2)
    54  cc := 1 + 2i
    55  if c != cc {
    56  	panic("ERROR")
    57  }
    58  
    59  if real(c) != 1.0 {
    60  	panic("ERROR")
    61  }
    62  
    63  if imag(c) != 2.0 {
    64  	panic("ERROR")
    65  }
    66  
    67  c1 := complex(real(complex(1, 2)), imag(complex(1, 2)))
    68  if c1 != complex(1, 2) {
    69  	panic("ERROR")
    70  }
    71  
    72  c2 := complex(2, 3)
    73  c3 := c1 + c2
    74  
    75  if real(c3) != 3 {
    76  	panic("ERROR")
    77  }
    78  
    79  if imag(c3) != 5 {
    80  	panic("ERROR")
    81  }
    82  
    83  func add(c1, c2 complex128) complex128 {
    84  	return c1 + c2
    85  }
    86  
    87  if add(c1, c2) != c3 {
    88  	panic("ERROR")
    89  }
    90  
    91  print("OK")