brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · ceececa Raw
70 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//   sin(const complex<T>& x);14 15#include <complex>16#include <cassert>17 18#include "test_macros.h"19#include "../cases.h"20 21template <class T>22void23test(const std::complex<T>& c, std::complex<T> x)24{25    assert(sin(c) == x);26}27 28template <class T>29void30test()31{32    test(std::complex<T>(0, 0), std::complex<T>(0, 0));33}34 35void test_edges()36{37    const unsigned N = sizeof(testcases) / sizeof(testcases[0]);38    for (unsigned i = 0; i < N; ++i)39    {40        std::complex<double> r = sin(testcases[i]);41        std::complex<double> t1(-imag(testcases[i]), real(testcases[i]));42        std::complex<double> t2 = sinh(t1);43        std::complex<double> z(imag(t2), -real(t2));44        if (std::isnan(real(r)))45            assert(std::isnan(real(z)));46        else47        {48            assert(real(r) == real(z));49            assert(std::signbit(real(r)) == std::signbit(real(z)));50        }51        if (std::isnan(imag(r)))52            assert(std::isnan(imag(z)));53        else54        {55            assert(imag(r) == imag(z));56            assert(std::signbit(imag(r)) == std::signbit(imag(z)));57        }58    }59}60 61int main(int, char**)62{63    test<float>();64    test<double>();65    test<long double>();66    test_edges();67 68  return 0;69}70