mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-01-30 20:12:17 +00:00
long double seems to work in all tests, but float128 has some constructor missing.
This commit is contained in:
@@ -9,19 +9,33 @@
|
||||
// Basic I/O tests for cpp_double_float<>
|
||||
// Note that the I/O of cpp_double_float<> is currently extremely underdeveloped
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/multiprecision/cpp_double_float.hpp>
|
||||
#ifdef BOOST_MATH_USE_FLOAT128
|
||||
#include <boost/multiprecision/float128.hpp>
|
||||
#endif
|
||||
#include <boost/random/uniform_real_distribution.hpp>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
|
||||
namespace test_cpp_double_float_io {
|
||||
|
||||
// TODO: this looks like a duplicate from test_cpp_double_float_comparision.cpp file.
|
||||
template<typename FloatingPointType> constexpr bool is_floating_point = std::is_floating_point<FloatingPointType>::value
|
||||
#ifdef BOOST_MATH_USE_FLOAT128
|
||||
or std::is_same<FloatingPointType,boost::multiprecision::float128>::value
|
||||
#endif
|
||||
;
|
||||
|
||||
template <typename FloatingPointType,
|
||||
typename std::enable_if<std::is_floating_point<FloatingPointType>::value, bool>::type = true>
|
||||
typename std::enable_if<is_floating_point<FloatingPointType>, bool>::type = true>
|
||||
FloatingPointType uniform_real()
|
||||
{
|
||||
//static std::random_device rd;
|
||||
static std::mt19937 gen /*(rd())*/;
|
||||
static std::uniform_real_distribution<FloatingPointType> dis(0.0, 1.0);
|
||||
static boost::random::uniform_real_distribution<FloatingPointType> dis(0.0, 1.0);
|
||||
|
||||
return dis(gen);
|
||||
}
|
||||
@@ -38,12 +52,13 @@ int rand_in_range(int a, int b)
|
||||
return a + int(float(b - a) * uniform_real<float>());
|
||||
}
|
||||
|
||||
template <typename FloatingPointType, typename std::enable_if<std::is_floating_point<FloatingPointType>::value>::type const* = nullptr>
|
||||
template <typename FloatingPointType, typename std::enable_if<is_floating_point<FloatingPointType>>::type const* = nullptr>
|
||||
FloatingPointType log_rand()
|
||||
{
|
||||
if (uniform_real<float>() < (1. / 100.))
|
||||
return 0; // throw in a few zeroes
|
||||
return std::ldexp(uniform_real<FloatingPointType>(), rand_in_range(std::numeric_limits<boost::multiprecision::backends::cpp_double_float<FloatingPointType> >::min_exponent, std::numeric_limits<boost::multiprecision::backends::cpp_double_float<FloatingPointType> >::max_exponent));
|
||||
using std::ldexp;
|
||||
return ldexp(uniform_real<FloatingPointType>(), rand_in_range(std::numeric_limits<boost::multiprecision::backends::cpp_double_float<FloatingPointType> >::min_exponent, std::numeric_limits<boost::multiprecision::backends::cpp_double_float<FloatingPointType> >::max_exponent));
|
||||
}
|
||||
|
||||
template <typename FloatingPointType>
|
||||
@@ -59,7 +74,8 @@ void test()
|
||||
FloatingPointType d = log_rand<FloatingPointType>();
|
||||
double_float_t d_ = d;
|
||||
|
||||
if (uniform_real<float>() > 0.66 && std::log10(d) + 1 < std::numeric_limits<FloatingPointType>::digits10)
|
||||
using std::log10;
|
||||
if (uniform_real<float>() > 0.66 && log10(d) + 1 < std::numeric_limits<FloatingPointType>::digits10)
|
||||
ss1.setf(std::ios::fixed);
|
||||
else if (uniform_real<float>() > 0.33)
|
||||
ss1.setf(std::ios::scientific);
|
||||
@@ -82,7 +98,7 @@ void test()
|
||||
int p = static_cast<int>(uniform_real<float>() * std::numeric_limits<FloatingPointType>::digits10);
|
||||
if ((ss1.flags() & std::ios::fixed) && d > 0)
|
||||
{
|
||||
p = std::min(p, std::numeric_limits<FloatingPointType>::digits10 - (int)std::log10(d) - 1);
|
||||
p = (std::min)(p, std::numeric_limits<FloatingPointType>::digits10 - (int)log10(d) - 1);
|
||||
}
|
||||
|
||||
ss1.precision(p);
|
||||
@@ -129,8 +145,13 @@ void test()
|
||||
|
||||
int main()
|
||||
{
|
||||
test_cpp_double_float_io::test<double>();
|
||||
test_cpp_double_float_io::test<float>();
|
||||
test_cpp_double_float_io::test<double>();
|
||||
test_cpp_double_float_io::test<long double>();
|
||||
#ifdef BOOST_MATH_USE_FLOAT128
|
||||
// FIXME:
|
||||
// test_cpp_double_float_io::test<boost::multiprecision::float128>();
|
||||
#endif
|
||||
|
||||
std::cin.get();
|
||||
std::cin.get();
|
||||
|
||||
Reference in New Issue
Block a user