test_cpp_dec_float_conv.cpp 948 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. #ifdef _MSC_VER
  7. #define _SCL_SECURE_NO_WARNINGS
  8. #endif
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/array.hpp>
  11. #include "test.hpp"
  12. #include <boost/multiprecision/cpp_dec_float.hpp>
  13. int main()
  14. {
  15. using namespace boost::multiprecision;
  16. //
  17. // Test interconversions between different precisions:
  18. //
  19. cpp_dec_float_50 f1(2);
  20. cpp_dec_float_100 f2(3);
  21. cpp_dec_float_100 f3 = f1; // implicit conversion OK
  22. BOOST_TEST(f3 == 2);
  23. cpp_dec_float_50 f4(f2); // explicit conversion OK
  24. BOOST_TEST(f4 == 3);
  25. f2 = f1;
  26. BOOST_TEST(f2 == 2);
  27. f2 = 4;
  28. f1 = static_cast<cpp_dec_float_50>(f2);
  29. BOOST_TEST(f1 == 4);
  30. return boost::report_errors();
  31. }