boost/libs/multiprecision/test/test_cpp_dec_float_conv.cpp

39 lines
948 B
C++
Raw Normal View History

2018-01-12 21:47:58 +01:00
///////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
2021-10-05 21:37:46 +02:00
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
2018-01-12 21:47:58 +01:00
//
#ifdef _MSC_VER
2021-10-05 21:37:46 +02:00
#define _SCL_SECURE_NO_WARNINGS
2018-01-12 21:47:58 +01:00
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/array.hpp>
#include "test.hpp"
#include <boost/multiprecision/cpp_dec_float.hpp>
int main()
{
using namespace boost::multiprecision;
//
// Test interconversions between different precisions:
//
2021-10-05 21:37:46 +02:00
cpp_dec_float_50 f1(2);
cpp_dec_float_100 f2(3);
2018-01-12 21:47:58 +01:00
2021-10-05 21:37:46 +02:00
cpp_dec_float_100 f3 = f1; // implicit conversion OK
2018-01-12 21:47:58 +01:00
BOOST_TEST(f3 == 2);
2021-10-05 21:37:46 +02:00
cpp_dec_float_50 f4(f2); // explicit conversion OK
2018-01-12 21:47:58 +01:00
BOOST_TEST(f4 == 3);
f2 = f1;
BOOST_TEST(f2 == 2);
f2 = 4;
f1 = static_cast<cpp_dec_float_50>(f2);
BOOST_TEST(f1 == 4);
return boost::report_errors();
}