| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <complex> |
| 10 | |
| 11 | // complex& operator/=(const complex& rhs); // constexpr in C++20 |
| 12 | |
| 13 | #include <cassert> |
| 14 | #include <complex> |
| 15 | |
| 16 | #include "floating_pointer_helpers.h" |
| 17 | #include "test_macros.h" |
| 18 | |
| 19 | template <class T> |
| 20 | TEST_CONSTEXPR_CXX20 |
| 21 | bool |
| 22 | test() |
| 23 | { |
| 24 | std::complex<T> c(-4, 7.5); |
| 25 | const std::complex<T> c2(1.5, 2.5); |
| 26 | assert(is_close(c.real(), T(-4))); |
| 27 | assert(is_close(c.imag(), T(7.5))); |
| 28 | c /= c2; |
| 29 | assert(is_close(c.real(), T(1.5))); |
| 30 | assert(is_close(c.imag(), T(2.5))); |
| 31 | c /= c2; |
| 32 | assert(is_close(c.real(), T(1))); |
| 33 | assert(is_close(c.imag(), T(0))); |
| 34 | |
| 35 | std::complex<T> c3; |
| 36 | |
| 37 | c3 = c; |
| 38 | std::complex<int> ic (1,1); |
| 39 | c3 /= ic; |
| 40 | assert(is_close(c3.real(), T(0.5))); |
| 41 | assert(is_close(c3.imag(), T(-0.5))); |
| 42 | |
| 43 | c3 = c; |
| 44 | std::complex<float> fc (1,1); |
| 45 | c3 /= fc; |
| 46 | assert(is_close(c3.real(), T(0.5))); |
| 47 | assert(is_close(c3.imag(), T(-0.5))); |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | int main(int, char**) |
| 52 | { |
| 53 | test<float>(); |
| 54 | test<double>(); |
| 55 | test<long double>(); |
| 56 | |
| 57 | #if TEST_STD_VER >= 20 |
| 58 | static_assert(test<float>()); |
| 59 | static_assert(test<double>()); |
| 60 | static_assert(test<long double>()); |
| 61 | #endif |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |