Opened 7 years ago
Closed 7 years ago
#11764 closed Bugs (fixed)
boost/multiprecision/number.hpp:52:17: error: no viable overloaded '='
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.58.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Summary
The following simple program attempts to make use of simple features in Boost Multiprecision and Math. I have no problem using constants::pi
with double, extended double, quad precision, or even a user-defined version of double double precision. However, when I try to get a single precision version of this constant, it fails.
Source Code
#include <iostream> #include <utility> #include <boost/math/constants/constants.hpp> #include <boost/multiprecision/cpp_bin_float.hpp> using boost::multiprecision::cpp_bin_float_single; using boost::multiprecision::cpp_bin_float_double; typedef boost::multiprecision::cpp_bin_float_single f32; typedef boost::multiprecision::cpp_bin_float_double f64; int main(void) { #if BUGTEST_PRECISION == 32 //f32 pi32 = boost::math::constants::pi<f32, boost::math::policies::policy<boost::math::policies::digits2<32> > >(); f32 pi32 = boost::math::constants::pi<f32>(); std::cout << pi32 << std::endl; #elif BUGTEST_PRECISION == 64 //f64 pi64 = boost::math::constants::pi<f64, boost::math::policies::policy<boost::math::policies::digits2<64> > >(); f64 pi64 = boost::math::constants::pi<f64>(); std::cout << pi64 << std::endl; #else #error Set BUGTEST_PRECISION to 32 or 64. #endif return 0; }
Compilers Tested
Mac Yosemite (10.10.5):
- Apple LLVM version 7.0.0 (
clang++
) - Clang 3.6.2 from Homebrew
- GCC 4.2.1 ({g++})
- GCC 5.2.0 from Homebrew
- Intel 16.0.0
Representative Output
Clang and GCC show nearly identical errors. The Intel one is much shorter but seemingly equivalent.
jrhammon-mac01:boost jrhammon$ clang++ -g -Wall -std=c++11 -stdlib=libc++ -DBUGTEST_PRECISION=64 bug.cc -o bug.x jrhammon-mac01:boost jrhammon$ clang++ -g -Wall -std=c++11 -stdlib=libc++ -DBUGTEST_PRECISION=32 bug.cc -o bug.x In file included from bug.cc:5: In file included from /usr/local/include/boost/multiprecision/cpp_bin_float.hpp:9: In file included from /usr/local/include/boost/multiprecision/cpp_int.hpp:12: /usr/local/include/boost/multiprecision/number.hpp:52:17: error: no viable overloaded '=' m_backend = canonical_value(v); ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~ /usr/local/include/boost/math/constants/constants.hpp:289:3: note: in instantiation of function template specialization 'boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127>, boost::multiprecision::expression_template_option::et_off>::number<float>' requested here BOOST_DEFINE_MATH_CONSTANT(pi, 3.141592653589793238462643383279502884e+00, "3.141592653589793238462643383279502884197169... ^ /usr/local/include/boost/math/constants/constants.hpp:246:13: note: expanded from macro 'BOOST_DEFINE_MATH_CONSTANT' { return BOOST_JOIN(x, F); }\ ^ /usr/local/include/boost/config/suffix.hpp:544:28: note: expanded from macro 'BOOST_JOIN' #define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y ) ^ /usr/local/include/boost/config/suffix.hpp:545:31: note: expanded from macro 'BOOST_DO_JOIN' #define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y) ^ /usr/local/include/boost/config/suffix.hpp:546:32: note: expanded from macro 'BOOST_DO_JOIN2' #define BOOST_DO_JOIN2( X, Y ) X##Y ^ <scratch space>:14:1: note: expanded from here 3.141592653589793238462643383279502884e+00F ^ /usr/local/include/boost/multiprecision/cpp_bin_float.hpp:107:19: note: candidate function not viable: no known conversion from 'typename boost::disable_if<is_same<typename detail::canonical<float, cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127> >::type, float>, typename detail::canonical<float, cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127> >::type>::type' (aka 'double') to 'const boost::multiprecision::backends::cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127>' for 1st argument cpp_bin_float& operator=(const cpp_bin_float &o) BOOST_NOEXCEPT_IF(noexcept(std::declval<rep_type&>() = std::declval<co... ^ /usr/local/include/boost/multiprecision/cpp_bin_float.hpp:303:19: note: candidate function not viable: no known conversion from 'typename boost::disable_if<is_same<typename detail::canonical<float, cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127> >::type, float>, typename detail::canonical<float, cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127> >::type>::type' (aka 'double') to 'const char *' for 1st argument cpp_bin_float& operator=(const char *s); ^ /usr/local/include/boost/multiprecision/cpp_bin_float.hpp:116:19: note: candidate template ignored: could not match 'cpp_bin_float<Digits, DigitBase, type-parameter-0-2, type-parameter-0-3, MinExponent, MaxExponent>' against 'double' cpp_bin_float& operator=(const cpp_bin_float<D, B, A, E, MinE, MaxE> &o) ^ /usr/local/include/boost/multiprecision/cpp_bin_float.hpp:129:74: note: candidate template ignored: substitution failure [with Float = double]: no type named 'type' in 'boost::enable_if_c<false, boost::multiprecision::backends::cpp_bin_float<24, boost::multiprecision::backends::digit_base_type::digit_base_2, void, short, -126, 127> &>' && (std::numeric_limits<Float>::radix == 2), cpp_bin_float&>::type operator=(const Float& f) ~~~~ ^ /usr/local/include/boost/multiprecision/cpp_bin_float.hpp:271:30: note: candidate template ignored: disabled by 'enable_if' [with I = double] typename boost::enable_if<is_integral<I>, cpp_bin_float&>::type operator=(const I& i) ^ 1 error generated.
Attachments (6)
Change History (7)
by , 7 years ago
comment:1 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks for the report, looks like I got the conversions and what is and is not permitted slightly wrong. Fixed in https://github.com/boostorg/multiprecision/commit/7dfea115f8ddd78ef19a1d60bff04ecc93df7253
source file that fails