brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · c56123a Raw
71 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<Arithmetic T>12//   T13//   norm(T x); // constexpr in C++2014 15#include <complex>16#include <type_traits>17#include <cassert>18 19#include "test_macros.h"20#include "../cases.h"21 22template <class T>23TEST_CONSTEXPR_CXX2024void25test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)26{27    static_assert((std::is_same<decltype(std::norm(x)), double>::value), "");28    assert(std::norm(x) == norm(std::complex<double>(static_cast<double>(x), 0)));29}30 31template <class T>32TEST_CONSTEXPR_CXX2033void34test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)35{36    static_assert((std::is_same<decltype(std::norm(x)), T>::value), "");37    assert(std::norm(x) == norm(std::complex<T>(x, 0)));38}39 40template <class T>41TEST_CONSTEXPR_CXX2042bool43test()44{45    test<T>(0);46    test<T>(1);47    test<T>(10);48    return true;49}50 51int main(int, char**)52{53    test<float>();54    test<double>();55    test<long double>();56    test<int>();57    test<unsigned>();58    test<long long>();59 60#if TEST_STD_VER >= 2061    static_assert(test<float>());62    static_assert(test<double>());63    static_assert(test<long double>());64    static_assert(test<int>());65    static_assert(test<unsigned>());66    static_assert(test<long long>());67#endif68 69    return 0;70}71