Skip to content

Commit

Permalink
Merge pull request #252 from anarthal/bugfix/249-quadmath-usage-requi…
Browse files Browse the repository at this point in the history
…rement

Made BOOST_CHARCONV_HAS_QUADMATH a usage requirement in the Jamfile
  • Loading branch information
mborland authored Jan 3, 2025
2 parents ffd3e71 + 0cd42b7 commit 3133adc
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 26 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ target_link_libraries(boost_charconv
# Check to see if the user specified BOOST_CHARCONV_NO_QUADMATH even with quadmath support being available
if(NOT BOOST_CHARCONV_QUADMATH_FOUND OR BOOST_CHARCONV_NO_QUADMATH)
message(STATUS "Boost.Charconv: quadmath support OFF")
target_compile_definitions(boost_charconv PUBLIC BOOST_CHARCONV_NO_QUADMATH)
else()
message(STATUS "Boost.Charconv: quadmath support ON")
target_compile_definitions(boost_charconv PUBLIC BOOST_CHARCONV_HAS_QUADMATH)
Expand Down
2 changes: 2 additions & 0 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ lib boost_charconv
# usage-requirements
: <link>shared:<define>BOOST_CHARCONV_DYN_LINK=1
<define>BOOST_CHARCONV_NO_LIB=1

[ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : <library>"quadmath" <define>BOOST_CHARCONV_HAS_QUADMATH ]
;
4 changes: 2 additions & 2 deletions include/boost/charconv/detail/buffer_sizing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ inline int get_real_precision(int precision = -1) noexcept

int real_precision;
BOOST_IF_CONSTEXPR (!std::is_same<Real, long double>::value
#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
&& !std::is_same<Real, __float128>::value
#endif
)
Expand All @@ -35,7 +35,7 @@ inline int get_real_precision(int precision = -1) noexcept
}
else
{
#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
BOOST_CHARCONV_IF_CONSTEXPR (std::is_same<Real, __float128>::value)
{
real_precision = 33;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/charconv/detail/issignaling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace boost { namespace charconv { namespace detail {
template <typename T>
inline bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept;

#if BOOST_CHARCONV_LDBL_BITS == 128
#if BOOST_CHARCONV_LDBL_BITS == 128 || defined(BOOST_CHARCONV_HAS_QUADMATH)

struct words128
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/charconv/detail/ryu/ryu_generic_128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch
if (precision > 0)
{
result[current_len++] = '.';
memset(result+current_len, '0', precision);
memset(result+current_len, '0', static_cast<size_t>(precision));
current_len += precision;
precision = 0;
}
Expand Down
12 changes: 6 additions & 6 deletions include/boost/charconv/from_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ BOOST_CHARCONV_DECL from_chars_result from_chars_erange(boost::core::string_view
BOOST_CHARCONV_DECL from_chars_result from_chars_erange(boost::core::string_view sv, long double& value, chars_format fmt = chars_format::general) noexcept;
#endif

#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
BOOST_CHARCONV_DECL from_chars_result from_chars_erange(boost::core::string_view sv, __float128& value, chars_format fmt = chars_format::general) noexcept;
#endif

Expand All @@ -186,7 +186,7 @@ BOOST_CHARCONV_DECL from_chars_result from_chars_erange(boost::core::string_view
#ifdef BOOST_CHARCONV_HAS_FLOAT64
BOOST_CHARCONV_DECL from_chars_result from_chars_erange(boost::core::string_view sv, std::float64_t& value, chars_format fmt = chars_format::general) noexcept;
#endif
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_FLOAT128)
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_QUADMATH)
BOOST_CHARCONV_DECL from_chars_result from_chars_erange(boost::core::string_view sv, std::float128_t& value, chars_format fmt = chars_format::general) noexcept;
#endif
#ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
Expand All @@ -204,7 +204,7 @@ BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char*
BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, long double& value, chars_format fmt = chars_format::general) noexcept;
#endif

#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, __float128& value, chars_format fmt = chars_format::general) noexcept;
#endif
#ifdef BOOST_CHARCONV_HAS_FLOAT16
Expand All @@ -216,7 +216,7 @@ BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char*
#ifdef BOOST_CHARCONV_HAS_FLOAT64
BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, std::float64_t& value, chars_format fmt = chars_format::general) noexcept;
#endif
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_FLOAT128)
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_QUADMATH)
BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, std::float128_t& value, chars_format fmt = chars_format::general) noexcept;
#endif
#ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
Expand All @@ -230,7 +230,7 @@ BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, do
BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, long double& value, chars_format fmt = chars_format::general) noexcept;
#endif

#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, __float128& value, chars_format fmt = chars_format::general) noexcept;
#endif
#ifdef BOOST_CHARCONV_HAS_FLOAT16
Expand All @@ -242,7 +242,7 @@ BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, st
#ifdef BOOST_CHARCONV_HAS_FLOAT64
BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, std::float64_t& value, chars_format fmt = chars_format::general) noexcept;
#endif
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_FLOAT128)
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_QUADMATH)
BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, std::float128_t& value, chars_format fmt = chars_format::general) noexcept;
#endif
#ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
Expand Down
6 changes: 2 additions & 4 deletions src/float128_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <quadmath.h>

#define BOOST_CHARCONV_HAS_FLOAT128

namespace boost {
namespace charconv {

Expand Down Expand Up @@ -92,7 +90,7 @@ inline __float128 to_float128(Unsigned_Integer w) noexcept
template <>
inline __float128 to_float128<uint128>(uint128 w) noexcept
{
return ldexp(static_cast<__float128>(w.high), 64) + static_cast<__float128>(w.low);
return ldexpq(static_cast<__float128>(w.high), 64) + static_cast<__float128>(w.low);
}

template <typename Unsigned_Integer, typename ArrayPtr>
Expand Down Expand Up @@ -354,6 +352,6 @@ inline bool issignaling<__float128> BOOST_PREVENT_MACRO_SUBSTITUTION (__float128
} //namespace charconv
} //namespace boost

#endif //BOOST_CHARCONV_HAS_FLOAT128
#endif //BOOST_CHARCONV_HAS_QUADMATH

#endif //BOOST_CHARCONV_FLOAT128_IMPL_HPP
10 changes: 5 additions & 5 deletions src/to_chars_float_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ inline to_chars_result to_chars_nonfinite(char* first, char* last, Real value, i

#endif // BOOST_CHARCONV_LDBL_BITS == 128

#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH

// GCC-5 evaluates the following specialization for other types
#if defined(__GNUC__) && __GNUC__ == 5
Expand Down Expand Up @@ -200,7 +200,7 @@ inline to_chars_result to_chars_nonfinite<__float128>(char* first, char* last, _
# pragma GCC diagnostic pop
#endif

#endif // BOOST_CHARCONV_HAS_FLOAT128
#endif // BOOST_CHARCONV_HAS_QUADMATH

template <typename Unsigned_Integer, typename Real, typename std::enable_if<!std::is_same<Unsigned_Integer, uint128>::value, bool>::type = true>
Unsigned_Integer convert_value(Real value) noexcept
Expand Down Expand Up @@ -273,7 +273,7 @@ to_chars_result to_chars_hex(char* first, char* last, Real value, int precision)

typename std::conditional<std::is_same<Real, float>::value, ieee754_binary32,
typename std::conditional<std::is_same<Real, double>::value, ieee754_binary64,
#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
typename std::conditional<std::is_same<Real, __float128>::value, ieee754_binary128,
#endif
#if BOOST_CHARCONV_LDBL_BITS == 128
Expand All @@ -283,7 +283,7 @@ to_chars_result to_chars_hex(char* first, char* last, Real value, int precision)
#else
ieee754_binary64
#endif
#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
>::type
#endif
>::type>::type
Expand Down Expand Up @@ -843,7 +843,7 @@ to_chars_result to_chars_float_impl(char* first, char* last, long double value,

#endif

#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH

template <>
to_chars_result to_chars_float_impl(char* first, char* last, __float128 value, chars_format fmt, int precision) noexcept
Expand Down
4 changes: 2 additions & 2 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ run test_boost_json_values.cpp ;
run to_chars_float_STL_comp.cpp : : : [ requires cxx17_hdr_charconv ] ;
run from_chars_float2.cpp ;
run-fail STL_benchmark.cpp : : : [ requires cxx17_hdr_charconv ] [ check-target-builds ../config//has_double_conversion "Google double-coversion support" : <library>"double-conversion" ] ;
run test_float128.cpp : : : [ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : <library>"quadmath" ] ;
run test_float128.cpp ;
run P2497.cpp ;
run github_issue_110.cpp ;
run github_issue_122.cpp ;
run from_chars_string_view.cpp ;
run github_issue_152.cpp ;
run github_issue_152_float128.cpp : : : [ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : <library>"quadmath" ] ;
run github_issue_152_float128.cpp ;
run github_issue_154.cpp ;
#run github_issue_156.cpp ;
run github_issue_158.cpp ;
Expand Down
4 changes: 2 additions & 2 deletions test/github_issue_110.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main()
test<long double>();
#endif

#ifdef BOOST_CHARCONV_HAS_FLOAT128
#ifdef BOOST_CHARCONV_HAS_QUADMATH
test<__float128>();
#endif

Expand All @@ -60,7 +60,7 @@ int main()
#ifdef BOOST_CHARCONV_HAS_FLOAT64
test<std::float64_t>();
#endif
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_FLOAT128)
#if defined(BOOST_CHARCONV_HAS_STDFLOAT128) && defined(BOOST_CHARCONV_HAS_QUADMATH)
test<std::float128_t>();
#endif
#ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
Expand Down
2 changes: 2 additions & 0 deletions test/github_issue_152_float128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#ifdef BOOST_CHARCONV_HAS_QUADMATH

#include <quadmath.h>

std::ostream& operator<<( std::ostream& os, __float128 v )
{
char buffer[ 256 ] {};
Expand Down
2 changes: 1 addition & 1 deletion test/test_128bit_emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void test_bitwise_operators()

void test_memcpy()
{
#if defined(BOOST_CHARCONV_HAS_FLOAT128) && defined(BOOST_CHARCONV_HAS_INT128)
#if defined(BOOST_CHARCONV_HAS_QUADMATH) && defined(BOOST_CHARCONV_HAS_INT128)
__float128 fval = 1e4000Q;
boost::uint128_type ref;
trivial_uint128 cpyval;
Expand Down
3 changes: 2 additions & 1 deletion test/test_float128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#if defined(BOOST_CHARCONV_HAS_QUADMATH) && defined(BOOST_HAS_INT128)

#include <ostream>
#include <quadmath.h>

#ifdef BOOST_CHARCONV_HAS_STDFLOAT128
#include <charconv>
Expand Down Expand Up @@ -85,13 +86,13 @@ std::ostream& operator<<( std::ostream& os, boost::int128_type v )
#include <boost/charconv.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/detail/splitmix64.hpp>
#include <boost/charconv/detail/generate_nan.hpp>
#include <boost/charconv/detail/issignaling.hpp>
#include <limits>
#include <iostream>
#include <iomanip>
#include <string>
#include <random>
#include "../src/float128_impl.hpp"

constexpr int N = 1024;
static boost::detail::splitmix64 rng;
Expand Down

0 comments on commit 3133adc

Please sign in to comment.