Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / test_mpc_overloads.cpp
1 //  Copyright 2012 John Maddock. Distributed under the Boost
2 //  Software License, Version 1.0. (See accompanying file
3 //  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
4
5 #include <type_traits>
6 #include "test.hpp"
7 #include <boost/multiprecision/mpc.hpp>
8 #include <boost/math/constants/constants.hpp>
9
10 using boost::multiprecision::mpc_complex_100;
11
12 template <class Complex>
13 void test_overloads()
14 {
15    typedef typename Complex::value_type Real;
16    Complex                              ya = {5.2, 7.4};
17    Complex                              yb = {8.2, 7.3};
18    Real                                 h  = 0.0001;
19    auto                                 I0 = (ya + yb) * h;
20    Complex                              I1 = I0 / 2 + yb * h;
21
22    //I1 = I0;  // not supposed to work.
23
24    Complex                      z{2, 3};
25    typename Complex::value_type theta = 0.2;
26    int                          n     = 2;
27    using std::sin;
28    Complex arg = z * sin(theta) - n * theta;
29
30    using std::exp;
31    Real    v    = 0.2;
32    Real    cotv = 7.8;
33    Real    cscv = 8.2;
34    Complex den  = z + v * cscv * exp(-v * cotv);
35
36    boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<100> > a = 2;
37    boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<100> > b = 3;
38    /*
39   if (a <= b) {
40     b = a;
41   }*/
42 }
43
44 template <class F, class Real>
45 typename std::result_of_t<F(Real)> some_functional(F f, Real a, Real b)
46 {
47    if (a <= -boost::math::tools::max_value<Real>())
48    {
49       return f(a);
50    }
51
52    return f(b);
53 }
54
55 template <class Complex>
56 void test_functional()
57 {
58    typedef typename Complex::value_type Real;
59    auto                                 f      = [](Real x) -> Complex { Complex z(x, 3); return z; };
60    Real                                 a      = 0;
61    Real                                 b      = 1;
62    Complex                              result = some_functional(f, a, b);
63 }
64
65 int main()
66 {
67    test_overloads<mpc_complex_100>();
68    test_functional<mpc_complex_100>();
69 }