brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 817d6cd Raw
135 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <complex>10 11// template<class T>12//   complex<T>13//   operator*(const complex<T>& lhs, const complex<T>& rhs); // constexpr in C++2014 15// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200000016 17#include <complex>18#include <cassert>19 20#include "test_macros.h"21#include "../cases.h"22 23template <class T>24TEST_CONSTEXPR_CXX2025bool26test()27{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));31    return true;32}33 34// test edges35 36TEST_CONSTEXPR_CXX20 bool test_edges()37{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]);42 43    for (unsigned i = 0; i < N; ++i)44    {45        for (unsigned j = 0; j < N; ++j)46        {47            std::complex<double> r = testcases[i] * testcases[j];48            switch (classification[i])49            {50            case zero:51                switch (classification[j])52                {53                case zero:54                case non_zero:55                    assert(classify(r) == zero);56                    break;57                case inf:58                case NaN:59                case non_zero_nan:60                    assert(classify(r) == NaN);61                    break;62                }63                break;64            case non_zero:65                switch (classification[j])66                {67                case zero:68                    assert(classify(r) == zero);69                    break;70                case non_zero:71                    assert(classify(r) == non_zero);72                    break;73                case inf:74                    assert(classify(r) == inf);75                    break;76                case NaN:77                case non_zero_nan:78                    assert(classify(r) == NaN);79                    break;80                }81                break;82            case inf:83                switch (classification[j])84                {85                case zero:86                case NaN:87                    assert(classify(r) == NaN);88                    break;89                case non_zero:90                case inf:91                case non_zero_nan:92                    assert(classify(r) == inf);93                    break;94                }95                break;96            case NaN:97                assert(classify(r) == NaN);98                break;99            case non_zero_nan:100                switch (classification[j])101                {102                case inf:103                    assert(classify(r) == inf);104                    break;105                case zero:106                case non_zero:107                case NaN:108                case non_zero_nan:109                    assert(classify(r) == NaN);110                    break;111                }112                break;113            }114        }115    }116    return true;117}118 119int main(int, char**)120{121    test<float>();122    test<double>();123    test<long double>();124    test_edges();125 126#if TEST_STD_VER > 17127    static_assert(test<float>());128    static_assert(test<double>());129    static_assert(test<long double>());130    static_assert(test_edges());131#endif132 133  return 0;134}135