Hi,
I'm having trouble compiling code that contains float128 data type.
I'm using MacOS Big Sur 11.4.
Compiler: gcc version 11.1.0 (Homebrew GCC 11.1.0_1)
I have no other problems with Boost, the only problem is when I use float128.
Please note that I have no problem compiling using libquadmath without using Boost using the __float128 data type.
I use Visual Studio Code:
"tasks": [
{
"label": "Build with g++ 11",
"type": "shell",
"command": "g++-11",
"args": [
"-g",
"-I/usr/local/Cellar/boost/1.76.0/include/",
"-I/usr/local/include/",
"-L/usr/local/Cellar/boost/1.76.0/lib/",
"-L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/",
"-L/usr/local/Cellar/gmp/6.2.1/lib/",
"-L/usr/local/Cellar/mpfr/4.1.0/lib/",
"-lmpfr",
"-lgmp",
"-lquadmath",
"-lboost_system",
"-lboost_filesystem",
"-std=c++20",
"'-fext-numeric-literals'",
"float128_example.cpp",
"-o",
"main"
],
"group": {
"kind": "build",
"isDefault": true
}
},
There are other libraries (gmp, mpfr, ...) because I have compiled several examples taken from the Boost site (such as, for example, automatic_differentation.cpp, GMP_example.cpp, MPFR_example.cpp etc.) and they all compile and run correctly.
I tried to compile the following example:
#include // For float_64_t, float128_t. Must be first include!
//#include
#include
#include // For gamma function.
#include // For constants pi, e ...
#include <typeinfo> //
#include <cmath> // for pow function.
int main()
{
try
{
//[float128_example_3
// Always use try'n'catch blocks to ensure any error messages are displayed.
//`Ensure that all possibly significant digits (17) including trailing zeros are shown.
std::cout.precision(std::numeric_limitsboost::float64_t::max_digits10);
std::cout.setf(std::ios::showpoint); // Show all significant trailing zeros.
//] [/ float128_example_3]
#ifdef BOOST_FLOAT128_C
std::cout << "Floating-point type boost::float128_t is available." << std::endl;
std::cout << " std::numeric_limitsboost::float128_t::digits10 == "
<< std::numeric_limitsboost::float128_t::digits10 << std::endl;
std::cout << " std::numeric_limitsboost::float128_t::max_digits10 == "
<< std::numeric_limitsboost::float128_t::max_digits10 << std::endl;
#else
std::cout << "Floating-point type boost::float128_t is NOT available." << std::endl;
#endif
show_versions("");
using boost::multiprecision::float128; // Wraps, for example, __float128 or _Quad.
// or
//using namespace boost::multiprecision;
std::cout.precision(std::numeric_limits<float128>::max_digits10); // Show all potentially meaningful digits.
std::cout.setf(std::ios::showpoint); // Show all significant trailing zeros.
// float128 pi0 = boost::math::constants::pi(); // Compile fails - need to specify a type for the constant!
float128 pi1 = boost::math::constants::pi<float128>(); // Returns a constant of type float128.
std::cout << sqrt(pi1) << std::endl; // 1.77245385090551602729816748334114514
float128 pi2 = boost::math::constants::pi<__float128>();
// Constant of type __float128 gets converted to float128 on the assignment.
std::cout << sqrt(pi2) << std::endl; // 1.77245385090551602729816748334114514
// DIY decimal digit literal constant, with suffix Q.
float128 pi3 = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348Q;
std::cout << sqrt(pi3) << std::endl; // 1.77245385090551602729816748334114514
// Compare to ready-rolled sqrt(pi) constant from Boost.Math:
std::cout << boost::math::constants::root_pi<float128>() << std::endl; // 1.77245385090551602729816748334114514
// DIY decimal digit literal constant, without suffix Q, suffering seventeen silent digits loss of precision!
float128 pi4 = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348;
std::cout << sqrt(pi4) << std::endl; // 1.77245385090551599275151910313924857
…
…
what i get is:
Executing task: g++-11 -g -I/usr/local/Cellar/boost/1.76.0/include/ -I/usr/local/include/ -L/usr/local/Cellar/boost/1.76.0/lib/ -L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/ -L/usr/local/Cellar/gmp/6.2.1/lib/ -L/usr/local/Cellar/mpfr/4.1.0/lib/ -lmpfr -lgmp -lquadmath -lboost_system -lboost_filesystem -std=c++20 '-fext-numeric-literals' float128_example.cpp -o main <
float128_example.cpp: In function 'int main()':
float128_example.cpp:143:56: error: conversion from 'boost::math::constants::detail::constant_return<__float128, boost::math::policies::policy >::type' {aka '__float128'} to non-scalar type 'boost::multiprecision::float128' {aka 'boost::multiprecision::number'} requested
143 | float128 pi2 = boost::math::constants::pi<__float128>(); // Constant of type __float128 gets converted to float128 on the assignment.
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
float128_example.cpp:147:18: error: conversion from '__float128' to non-scalar type 'boost::multiprecision::float128' {aka 'boost::multiprecision::number'} requested
147 | float128 pi3 = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348Q;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float128_example.cpp:160:37: error: conversion from '__float128' to non-scalar type 'const float128' {aka 'const boost::multiprecision::number'} requested
160 | constexpr float128 pi_constexpr = 3.1415926535897932384626433832795028841971693993751058Q;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/boost/1.76.0/include/boost/math/special_functions/gamma.hpp:23,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/special_functions/detail/bessel_jy.hpp:14,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/special_functions/bessel.hpp:20,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/special_functions/airy.hpp:12,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/special_functions.hpp:15,
from float128_example.cpp:22:
float128_example.cpp:172:83: in 'constexpr' expansion of 'boost::math::constants::root_pi >()'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:237:54: error: 'constexpr typename boost::math::constants::detail::constant_return::type boost::math::constants::root_pi() [with T = boost::multiprecision::number; Policy = boost::math::policies::policy; typename boost::math::constants::detail::constant_return::type = const boost::multiprecision::number&]' called in a constant expression
237 | { return name >(); }\
| ^
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:269:3: note: in expansion of macro 'BOOST_DEFINE_MATH_CONSTANT'
269 | BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.772453850905516027298167483341145182e+00, "1.77245385090551602729816748334114518279754945612238712821380778985291128459103218137495065673854466541622682362e+00")
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:269:30: note: 'constexpr typename boost::math::constants::detail::constant_return::type boost::math::constants::root_pi() [with T = boost::multiprecision::number; Policy = boost::math::policies::policy; typename boost::math::constants::detail::constant_return::type = const boost::multiprecision::number&]' is not usable as a 'constexpr' function because:
269 | BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.772453850905516027298167483341145182e+00, "1.77245385090551602729816748334114518279754945612238712821380778985291128459103218137495065673854466541622682362e+00")
| ^~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:234:116: note: in definition of macro 'BOOST_DEFINE_MATH_CONSTANT'
234 | template inline BOOST_CONSTEXPR typename detail::constant_return::type name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T) BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(Policy)) BOOST_MATH_NOEXCEPT(T)\
| ^~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:235:57: error: call to non-'constexpr' function 'static const T& boost::math::constants::detail::constant_root_pi<T>::get(const std::integral_constant&) [with T = boost::multiprecision::number]'
235 | { return detail:: BOOST_JOIN(constant_, name)<T>::get(typename construction_traits::type()); }\
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:269:3: note: in expansion of macro 'BOOST_DEFINE_MATH_CONSTANT'
269 | BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.772453850905516027298167483341145182e+00, "1.77245385090551602729816748334114518279754945612238712821380778985291128459103218137495065673854466541622682362e+00")
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:207:27: note: 'static const T& boost::math::constants::detail::constant_root_pi<T>::get(const std::integral_constant&) [with T = boost::multiprecision::number]' declared here
207 | static inline const T& get(const std::integral_constant&)\
| ^~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:207:27: note: in definition of macro 'BOOST_DEFINE_MATH_CONSTANT'
207 | static inline const T& get(const std::integral_constant&)\
| ^~~
float128_example.cpp:186:20: error: call of overloaded 'exp(__float128)' is ambiguous
186 | float128 e1 = exp(1.Q); // Note argument to exp is type float128.
| ~~~^~~~~
In file included from /usr/local/Cellar/gcc/11.1.0_1/include/c++/11.1.0/cmath:45,
from /usr/local/Cellar/boost/1.76.0/include/boost/config/no_tr1/cmath.hpp:21,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/tools/config.hpp:19,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/cstdfloat/cstdfloat_types.hpp:18,
from /usr/local/Cellar/boost/1.76.0/include/boost/cstdfloat.hpp:18,
from float128_example.cpp:19:
/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin20/11.1.0/include-fixed/math.h:376:15: note: candidate: 'double exp(double)'
376 | extern double exp(double);
| ^~~
In file included from /usr/local/Cellar/boost/1.76.0/include/boost/config/no_tr1/cmath.hpp:21,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/tools/config.hpp:19,
from /usr/local/Cellar/boost/1.76.0/include/boost/math/cstdfloat/cstdfloat_types.hpp:18,
from /usr/local/Cellar/boost/1.76.0/include/boost/cstdfloat.hpp:18,
from float128_example.cpp:19:
/usr/local/Cellar/gcc/11.1.0_1/include/c++/11.1.0/cmath:226:3: note: candidate: 'constexpr long double std::exp(long double)'
226 | exp(long double __x)
| ^~~
/usr/local/Cellar/gcc/11.1.0_1/include/c++/11.1.0/cmath:222:3: note: candidate: 'constexpr float std::exp(float)'
222 | exp(float __x)
| ^~~
In file included from /usr/local/Cellar/boost/1.76.0/include/boost/math/cstdfloat/cstdfloat_types.hpp:17,
from /usr/local/Cellar/boost/1.76.0/include/boost/cstdfloat.hpp:18,
from float128_example.cpp:19:
/usr/local/Cellar/boost/1.76.0/include/boost/math/tools/precision.hpp: In instantiation of 'constexpr int boost::math::tools::digits() [with T = __float128]':
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'static const T& boost::math::constants::detail::constant_pi<T>::get_from_variable_precision() [with T = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'static T boost::math::constants::detail::constant_pi<T>::get(const std::integral_constant&) [with T = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'constexpr typename boost::math::constants::detail::constant_return::type boost::math::constants::pi() [with T = __float128; Policy = boost::math::policies::policy; typename boost::math::constants::detail::constant_return::type = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'constexpr typename boost::math::constants::detail::constant_return<T>::type boost::math::constants::pi() [with T = __float128; typename boost::math::constants::detail::constant_return<T>::type = __float128]'
float128_example.cpp:143:56: required from here
/usr/local/Cellar/boost/1.76.0/include/boost/math/tools/precision.hpp:44:51: error: static assertion failed: ::std::numeric_limits<T>::is_specialized
44 | BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
| ^~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/static_assert.hpp:70:55: note: in definition of macro 'BOOST_STATIC_ASSERT'
70 | # define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
| ^~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/tools/precision.hpp:44:51: note: 'std::__numeric_limits_base::is_specialized' evaluates to false
44 | BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
| ^~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/static_assert.hpp:70:55: note: in definition of macro 'BOOST_STATIC_ASSERT'
70 | # define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
| ^~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/tools/precision.hpp:45:62: error: static assertion failed: ::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10
45 | BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/static_assert.hpp:70:55: note: in definition of macro 'BOOST_STATIC_ASSERT'
70 | # define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
| ^~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/math/tools/precision.hpp:45:62: note: '((((int)std::__numeric_limits_base::radix) == 2) || (((int)std::__numeric_limits_base::radix) == 10))' evaluates to false
45 | BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/static_assert.hpp:70:55: note: in definition of macro 'BOOST_STATIC_ASSERT'
70 | # define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
| ^~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/detail/converter_lexical.hpp: In instantiation of 'struct boost::detail::deduce_target_char_impl >':
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/detail/converter_lexical.hpp:270:89: required from 'struct boost::detail::deduce_target_char<__float128>'
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/detail/converter_lexical.hpp:407:92: required from 'struct boost::detail::lexical_cast_stream_traits'
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/detail/converter_lexical.hpp:468:15: required from 'struct boost::detail::lexical_converter_impl<__float128, const char*>'
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/try_lexical_convert.hpp:201:44: required from 'bool boost::conversion::detail::try_lexical_convert(const Source&, Target&) [with Target = __float128; Source = const char*]'
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast.hpp:41:60: [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/local/Cellar/boost/1.76.0/include/boost/math/tools/convert_from_string.hpp:43:39: required from 'constexpr typename boost::math::tools::convert_from_string_result<T>::type boost::math::tools::convert_from_string(const char*) [with Real = __float128; typename boost::math::tools::convert_from_string_result<T>::type = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'static const T& boost::math::constants::detail::constant_pi<T>::get_from_variable_precision() [with T = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'static T boost::math::constants::detail::constant_pi<T>::get(const std::integral_constant&) [with T = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'constexpr typename boost::math::constants::detail::constant_return::type boost::math::constants::pi() [with T = __float128; Policy = boost::math::policies::policy; typename boost::math::constants::detail::constant_return::type = __float128]'
/usr/local/Cellar/boost/1.76.0/include/boost/math/constants/constants.hpp:259:3: required from 'constexpr typename boost::math::constants::detail::constant_return<T>::type boost::math::constants::pi() [with T = __float128; typename boost::math::constants::detail::constant_return<T>::type = __float128]'
float128_example.cpp:143:56: required from here
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/detail/converter_lexical.hpp:243:54: error: static assertion failed: Target type is neither std::istream`able nor std::wistream`able
243 | BOOST_STATIC_ASSERT_MSG((result_t::value || boost::has_right_shift, T >::value),
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/static_assert.hpp:31:59: note: in definition of macro 'BOOST_STATIC_ASSERT_MSG'
31 | # define BOOST_STATIC_ASSERT_MSG( ... ) static_assert(__VA_ARGS__)
| ^~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/lexical_cast/detail/converter_lexical.hpp:243:54: note: '(((bool)boost::integral_constant::value) || ((bool)boost::integral_constant::value))' evaluates to false
243 | BOOST_STATIC_ASSERT_MSG((result_t::value || boost::has_right_shift, T >::value),
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/boost/1.76.0/include/boost/static_assert.hpp:31:59: note: in definition of macro 'BOOST_STATIC_ASSERT_MSG'
31 | # define BOOST_STATIC_ASSERT_MSG( ... ) static_assert(__VA_ARGS__)
| ^~~~~~~~~~~
The terminal process "zsh '-c', 'g++-11 -g -I/usr/local/Cellar/boost/1.76.0/include/ -I/usr/local/include/ -L/usr/local/Cellar/boost/1.76.0/lib/ -L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/ -L/usr/local/Cellar/gmp/6.2.1/lib/ -L/usr/local/Cellar/mpfr/4.1.0/lib/ -lmpfr -lgmp -lquadmath -lboost_system -lboost_filesystem -std=c++20 '-fext-numeric-literals' float128_example.cpp -o main'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
Thanks
Stefano Gragnani
Inviato da iPad