test_mixed_float.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2012 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
  5. //
  6. // Compare arithmetic results using fixed_int to GMP results.
  7. //
  8. #ifdef _MSC_VER
  9. #define _SCL_SECURE_NO_WARNINGS
  10. #endif
  11. #ifdef TEST_GMP
  12. #include <boost/multiprecision/gmp.hpp>
  13. #endif
  14. #ifdef TEST_MPFR
  15. #include <boost/multiprecision/mpfr.hpp>
  16. #endif
  17. #include <boost/multiprecision/cpp_dec_float.hpp>
  18. #include "test.hpp"
  19. template <class Number, class BigNumber>
  20. void test()
  21. {
  22. using namespace boost::multiprecision;
  23. typedef Number test_type;
  24. test_type a = 1;
  25. a /= 3;
  26. test_type b = -a;
  27. BigNumber r;
  28. BOOST_CHECK_EQUAL(add(r, a, a), BigNumber(a) + BigNumber(a));
  29. BOOST_CHECK_EQUAL(subtract(r, a, b), BigNumber(a) - BigNumber(b));
  30. BOOST_CHECK_EQUAL(subtract(r, b, a), BigNumber(b) - BigNumber(a));
  31. BOOST_CHECK_EQUAL(multiply(r, a, a), BigNumber(a) * BigNumber(a));
  32. }
  33. int main()
  34. {
  35. using namespace boost::multiprecision;
  36. test<cpp_dec_float_50, cpp_dec_float_100>();
  37. #ifdef TEST_GMP
  38. test<mpf_float_50, mpf_float_100>();
  39. #endif
  40. #ifdef TEST_MPFR
  41. test<mpfr_float_50, mpfr_float_100>();
  42. #endif
  43. return boost::report_errors();
  44. }