Skip to content

Commit 7cc9985

Browse files
authored
Merge pull request #170 from BoostGSoC21/clarify_float128_type
Fix #163 and fix #168 and fix #169 via clarify use of boost::float128_type
2 parents d241147 + 06f2892 commit 7cc9985

16 files changed

+127
-303
lines changed

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
1111
#define BOOST_MP_CPP_DF_QF_DETAIL_2023_01_02_HPP
1212

1313
#include <boost/config.hpp>
14+
15+
#ifdef BOOST_HAS_FLOAT128
16+
# if __has_include(<quadmath.h>)
17+
# include <quadmath.h>
18+
# ifndef BOOST_MP_HAS_FLOAT128_SUPPORT
19+
# define BOOST_MP_HAS_FLOAT128_SUPPORT
20+
# endif
21+
# endif
22+
#endif
23+
1424
#include <boost/multiprecision/number.hpp>
25+
#include <boost/multiprecision/detail/float128_functions.hpp>
1526
#include <boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath.hpp>
1627

1728
#include <utility>

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
#include <boost/config.hpp>
1212

13-
#ifdef BOOST_HAS_FLOAT128
14-
#include <quadmath.h>
15-
#endif
16-
1713
#include <boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_fabs.hpp>
1814
#include <boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_floor.hpp>
1915
#include <boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_fma.hpp>

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_fabs.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2023.
2+
// Copyright Christopher Kormanyos 2023 - 2024.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_floor.hpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@ namespace boost { namespace multiprecision { namespace backends { namespace cpp_
1515

1616
namespace detail {
1717

18-
#if defined(BOOST_HAS_FLOAT128)
1918
template <class T>
20-
auto floor_impl(T x) -> typename ::std::enable_if<::std::is_same<T, ::boost::float128_type>::value, T>::type
19+
auto floor_impl(T x) -> T
2120
{
22-
return ::floorq(x);
23-
}
24-
#endif
25-
26-
template <class T>
27-
auto floor_impl(T x) -> typename ::std::enable_if<::std::is_floating_point<T>::value, T>::type
28-
{
29-
// Default to the regular std::floor function.
21+
// Default to the regular floor function.
3022
using std::floor;
3123

3224
return floor(x);

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_fma.hpp

+10-18
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,32 @@ namespace unsafe {
1717

1818
namespace detail {
1919

20-
#if defined(BOOST_HAS_FLOAT128)
2120
template <class T>
22-
auto fma_impl(T x, T y, T z) noexcept -> typename ::std::enable_if<::std::is_same<T, ::boost::float128_type>::value, T>::type
21+
inline auto fma_impl(T x, T y, T z) noexcept -> T
2322
{
24-
return ::fmaq(x);
23+
// Default to the written-out operations.
24+
25+
return (x * y) + z;
2526
}
26-
#endif
2727

2828
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__INTEL_LLVM_COMPILER)
29-
template <class T>
30-
auto fma_impl(T x, T y, T z) noexcept -> typename ::std::enable_if<::std::is_same<T, float>::value, T>::type
29+
template <>
30+
inline auto fma_impl<float>(float x, float y, float z) noexcept -> float
3131
{
3232
return __builtin_fmaf(x, y, z);
3333
}
3434

35-
template <class T>
36-
auto fma_impl(T x, T y, T z) noexcept -> typename ::std::enable_if<::std::is_same<T, double>::value, T>::type
35+
template <>
36+
inline auto fma_impl<double>(double x, double y, double z) noexcept -> double
3737
{
3838
return __builtin_fma(x, y, z);
3939
}
4040

41-
template <class T>
42-
auto fma_impl(T x, T y, T z) noexcept -> typename ::std::enable_if<::std::is_same<T, long double>::value, T>::type
41+
template <>
42+
inline auto fma_impl<long double>(long double x, long double y, long double z) noexcept -> long double
4343
{
4444
return __builtin_fmal(x, y, z);
4545
}
46-
#else
47-
template <class T>
48-
auto fma_impl(T x, T y, T z) noexcept -> typename ::std::enable_if<::std::is_floating_point<T>::value, T>::type
49-
{
50-
// Default to the written-out operations.
51-
52-
return (x * y) + z;
53-
}
5446
#endif
5547

5648
} // namespace detail

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_fpclassify.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
#include <boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_isnan.hpp>
1414

1515
#include <cmath>
16-
#include <type_traits>
1716

1817
namespace boost { namespace multiprecision { namespace backends { namespace cpp_df_qf_detail { namespace ccmath {
1918

2019
template <typename T>
21-
constexpr auto fpclassify(T x) -> typename std::enable_if<!std::is_integral<T>::value, int>::type
20+
constexpr auto fpclassify(T x) -> int
2221
{
2322
if ((::boost::multiprecision::backends::cpp_df_qf_detail::ccmath::isnan)(x))
2423
{
@@ -36,7 +35,7 @@ constexpr auto fpclassify(T x) -> typename std::enable_if<!std::is_integral<T>::
3635
{
3736
return FP_ZERO;
3837
}
39-
else if ((fabs_x > 0) && (fabs_x < (boost::multiprecision::backends::cpp_df_qf_detail::ccmath::numeric_limits<T>::min)()))
38+
else if ((fabs_x > 0) && (fabs_x < (::boost::multiprecision::backends::cpp_df_qf_detail::ccmath::numeric_limits<T>::min)()))
4039
{
4140
return FP_SUBNORMAL;
4241
}

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_frexp.hpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ namespace boost { namespace multiprecision { namespace backends { namespace cpp_
1616
namespace detail
1717
{
1818

19-
#if defined(BOOST_HAS_FLOAT128)
2019
template <class T>
21-
auto frexp_impl(T arg, int* expptr) -> typename ::std::enable_if<::std::is_same<T, ::boost::float128_type>::value, T>::type
20+
auto frexp_impl(T arg, int* expptr) -> T
2221
{
23-
return ::frexpq(arg, expptr);
24-
}
25-
#endif
26-
27-
template <class T>
28-
auto frexp_impl(T arg, int* expptr) -> typename ::std::enable_if<::std::is_floating_point<T>::value, T>::type
29-
{
30-
// Default to the regular std::frexp function.
22+
// Default to the regular frexp function.
3123
using std::frexp;
3224

3325
return frexp(arg, expptr);

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_isinf.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2023.
2+
// Copyright Christopher Kormanyos 2023 - 2024.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_isnan.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2023.
2+
// Copyright Christopher Kormanyos 2023 - 2024.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)

include/boost/multiprecision/cpp_df_qf/cpp_df_qf_detail_ccmath_ldexp.hpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@ namespace boost { namespace multiprecision { namespace backends { namespace cpp_
1515

1616
namespace detail {
1717

18-
#if defined(BOOST_HAS_FLOAT128)
1918
template <class T>
20-
auto ldexp_impl(T arg, int expval) -> typename ::std::enable_if<::std::is_same<T, ::boost::float128_type>::value, T>::type
19+
auto ldexp_impl(T arg, int expval) -> T
2120
{
22-
return ::ldexpq(arg, expval);
23-
}
24-
#endif
25-
26-
template <class T>
27-
auto ldexp_impl(T arg, int expval) -> typename ::std::enable_if<::std::is_floating_point<T>::value, T>::type
28-
{
29-
// Default to the regular std::ldexp function.
21+
// Default to the regular ldexp function.
3022
using std::ldexp;
3123

3224
return ldexp(arg, expval);

0 commit comments

Comments
 (0)