test_mpc_overloads.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <type_traits>
  5. #include "test.hpp"
  6. #include <boost/multiprecision/mpc.hpp>
  7. #include <boost/math/constants/constants.hpp>
  8. using boost::multiprecision::mpc_complex_100;
  9. template <class Complex>
  10. void test_overloads()
  11. {
  12. typedef typename Complex::value_type Real;
  13. Complex ya = {5.2, 7.4};
  14. Complex yb = {8.2, 7.3};
  15. Real h = 0.0001;
  16. auto I0 = (ya + yb) * h;
  17. Complex I1 = I0 / 2 + yb * h;
  18. //I1 = I0; // not supposed to work.
  19. Complex z{2, 3};
  20. typename Complex::value_type theta = 0.2;
  21. int n = 2;
  22. using std::sin;
  23. Complex arg = z * sin(theta) - n * theta;
  24. using std::exp;
  25. Real v = 0.2;
  26. Real cotv = 7.8;
  27. Real cscv = 8.2;
  28. Complex den = z + v * cscv * exp(-v * cotv);
  29. boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<100> > a = 2;
  30. boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<100> > b = 3;
  31. /*
  32. if (a <= b) {
  33. b = a;
  34. }*/
  35. }
  36. template <class F, class Real>
  37. typename std::result_of_t<F(Real)> some_functional(F f, Real a, Real b)
  38. {
  39. if (a <= -boost::math::tools::max_value<Real>())
  40. {
  41. return f(a);
  42. }
  43. return f(b);
  44. }
  45. template <class Complex>
  46. void test_functional()
  47. {
  48. typedef typename Complex::value_type Real;
  49. auto f = [](Real x) -> Complex { Complex z(x, 3); return z; };
  50. Real a = 0;
  51. Real b = 1;
  52. Complex result = some_functional(f, a, b);
  53. }
  54. int main()
  55. {
  56. test_overloads<mpc_complex_100>();
  57. test_functional<mpc_complex_100>();
  58. }