Home | History | Annotate | Download | only in complex.ops
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <complex>
     11 
     12 // template<class T>
     13 //   complex<T>
     14 //   operator/(const complex<T>& lhs, const complex<T>& rhs);
     15 
     16 #include <complex>
     17 #include <cassert>
     18 
     19 #include "../cases.h"
     20 
     21 template <class T>
     22 void
     23 test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x)
     24 {
     25     assert(lhs / rhs == x);
     26 }
     27 
     28 template <class T>
     29 void
     30 test()
     31 {
     32     std::complex<T> lhs(-4.0, 7.5);
     33     std::complex<T> rhs(1.5, 2.5);
     34     std::complex<T>   x(1.5, 2.5);
     35     test(lhs, rhs, x);
     36 }
     37 
     38 void test_edges()
     39 {
     40     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
     41     for (unsigned i = 0; i < N; ++i)
     42     {
     43         for (unsigned j = 0; j < N; ++j)
     44         {
     45             std::complex<double> r = testcases[i] / testcases[j];
     46             switch (classify(testcases[i]))
     47             {
     48             case zero:
     49                 switch (classify(testcases[j]))
     50                 {
     51                 case zero:
     52                     assert(classify(r) == NaN);
     53                     break;
     54                 case non_zero:
     55                     assert(classify(r) == zero);
     56                     break;
     57                 case inf:
     58                     assert(classify(r) == zero);
     59                     break;
     60                 case NaN:
     61                     assert(classify(r) == NaN);
     62                     break;
     63                 case non_zero_nan:
     64                     assert(classify(r) == NaN);
     65                     break;
     66                 }
     67                 break;
     68             case non_zero:
     69                 switch (classify(testcases[j]))
     70                 {
     71                 case zero:
     72                     assert(classify(r) == inf);
     73                     break;
     74                 case non_zero:
     75                     assert(classify(r) == non_zero);
     76                     break;
     77                 case inf:
     78                     assert(classify(r) == zero);
     79                     break;
     80                 case NaN:
     81                     assert(classify(r) == NaN);
     82                     break;
     83                 case non_zero_nan:
     84                     assert(classify(r) == NaN);
     85                     break;
     86                 }
     87                 break;
     88             case inf:
     89                 switch (classify(testcases[j]))
     90                 {
     91                 case zero:
     92                     assert(classify(r) == inf);
     93                     break;
     94                 case non_zero:
     95                     assert(classify(r) == inf);
     96                     break;
     97                 case inf:
     98                     assert(classify(r) == NaN);
     99                     break;
    100                 case NaN:
    101                     assert(classify(r) == NaN);
    102                     break;
    103                 case non_zero_nan:
    104                     assert(classify(r) == NaN);
    105                     break;
    106                 }
    107                 break;
    108             case NaN:
    109                 switch (classify(testcases[j]))
    110                 {
    111                 case zero:
    112                     assert(classify(r) == NaN);
    113                     break;
    114                 case non_zero:
    115                     assert(classify(r) == NaN);
    116                     break;
    117                 case inf:
    118                     assert(classify(r) == NaN);
    119                     break;
    120                 case NaN:
    121                     assert(classify(r) == NaN);
    122                     break;
    123                 case non_zero_nan:
    124                     assert(classify(r) == NaN);
    125                     break;
    126                 }
    127                 break;
    128             case non_zero_nan:
    129                 switch (classify(testcases[j]))
    130                 {
    131                 case zero:
    132                     assert(classify(r) == inf);
    133                     break;
    134                 case non_zero:
    135                     assert(classify(r) == NaN);
    136                     break;
    137                 case inf:
    138                     assert(classify(r) == NaN);
    139                     break;
    140                 case NaN:
    141                     assert(classify(r) == NaN);
    142                     break;
    143                 case non_zero_nan:
    144                     assert(classify(r) == NaN);
    145                     break;
    146                 }
    147                 break;
    148             }
    149         }
    150     }
    151 }
    152 
    153 int main()
    154 {
    155     test<float>();
    156     test<double>();
    157     test<long double>();
    158     test_edges();
    159 }
    160