1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // operator*(const complex<T>& lhs, const complex<T>& rhs); // constexpr in C++20
15 // ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=5000000
20 #include "test_macros.h"
28 const std::complex<T
> lhs(1.5, 2.5);
29 const std::complex<T
> rhs(1.5, 2.5);
30 assert(lhs
* rhs
== std::complex<T
>(-4.0, 7.5));
36 TEST_CONSTEXPR_CXX20
bool test_edges()
38 const unsigned N
= sizeof(testcases
) / sizeof(testcases
[0]);
39 int classification
[N
];
40 for (unsigned i
=0; i
< N
; ++i
)
41 classification
[i
] = classify(testcases
[i
]);
43 for (unsigned i
= 0; i
< N
; ++i
)
45 for (unsigned j
= 0; j
< N
; ++j
)
47 std::complex<double> r
= testcases
[i
] * testcases
[j
];
48 switch (classification
[i
])
51 switch (classification
[j
])
55 assert(classify(r
) == zero
);
60 assert(classify(r
) == NaN
);
65 switch (classification
[j
])
68 assert(classify(r
) == zero
);
71 assert(classify(r
) == non_zero
);
74 assert(classify(r
) == inf
);
78 assert(classify(r
) == NaN
);
83 switch (classification
[j
])
87 assert(classify(r
) == NaN
);
92 assert(classify(r
) == inf
);
97 assert(classify(r
) == NaN
);
100 switch (classification
[j
])
103 assert(classify(r
) == inf
);
109 assert(classify(r
) == NaN
);
119 int main(int, char**)
126 #if TEST_STD_VER > 17
127 static_assert(test
<float>());
128 static_assert(test
<double>());
129 static_assert(test
<long double>());
130 static_assert(test_edges());