This simple code can't be compiled with the -std=c++20
option:
#include <limits>
#include <boost/multiprecision/float128.hpp>
namespace bm = boost::multiprecision;
int main()
{
auto const m = std::numeric_limits<bm::float128>::max();
}
The compilation command:
g++ -std=c++20 -Wno-unused-but-set-variable test.cpp
The compiler complains about the BOOST_MP_QUAD_MAX
constant. Why is that?
Directly from the documentation :
When compiling with gcc, you need to use the flag
--std=gnu++11
/14
/17
, as the suffixQ
is a GNU extension. Compilation fails with the flag--std=c++11
/14
/17
unless you also use-fext-numeric-literals
.
The same applies for c++20
/ gnu++20
, the docs merely haven't yet been updated for that revision.
The documentation states:
When compiling with gcc, you need to use the flag --std=gnu++11/14/17, as the suffix 'Q' is a GNU extension. Compilation fails with the flag --std=c++11/14/17 unless you also use -fext-numeric-literals.
So you need to specify --std=gnu++20
instead of --std=c++20
. The boost documentation is not up-to-date. The flag enables various GNU extensions , one of it being __float128
.
See example on godbolt .
The underlying reason for the compiler error is that without the --std=gnu++17
or --std=gnu++20
flag, _GLIBCXX_USE_FLOAT128
is not defined, meaning BOOST_HAS_FLOAT128
is not defined, meaning __float128
is not recognized as number_kind_floating_point
(but as number_kind_unknown
). This means that boost::multiprecision::number
cannot be implicitly constructed from a __float128
because is_restricted_conversion<__float128, boost::multiprecision::float128_backend>::value
is true
because bm::detail::is_lossy_conversion<__float128, boost::multiprecision::float128_backend>::value
is true
, because __float128
is number_kind_unknown
instead of number_kind_floating_point
.
Ie in short, without gnu++20
, the boost::multiprecision::float128
type is broken.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.