Skip to content

Commit 0a0513d

Browse files
committed
long-double
1 parent b5955b4 commit 0a0513d

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

libcxx/include/__algorithm/radix_sort.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <__algorithm/move.h>
3232
#include <__bit/bit_cast.h>
3333
#include <__bit/bit_log2.h>
34-
#include <__bit/countl.h>
3534
#include <__config>
3635
#include <__cstddef/size_t.h>
3736
#include <__functional/identity.h>
@@ -44,12 +43,15 @@
4443
#include <__numeric/partial_sum.h>
4544
#include <__type_traits/decay.h>
4645
#include <__type_traits/enable_if.h>
46+
#include <__type_traits/integral_constant.h>
4747
#include <__type_traits/invoke.h>
4848
#include <__type_traits/is_assignable.h>
4949
#include <__type_traits/is_enum.h>
5050
#include <__type_traits/is_integral.h>
5151
#include <__type_traits/is_unsigned.h>
5252
#include <__type_traits/make_unsigned.h>
53+
#include <__type_traits/void_t.h>
54+
#include <__utility/declval.h>
5355
#include <__utility/forward.h>
5456
#include <__utility/integer_sequence.h>
5557
#include <__utility/move.h>
@@ -379,6 +381,20 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Floating __f) {
379381
template <class _Enum, enable_if_t< is_enum<_Enum>::value, int> = 0>
380382
_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Enum __e) = delete;
381383

384+
// `long double` varies significantly across platforms and compilers, making it practically
385+
// impossible to determine its actual bit width for conversion to an ordered integer.
386+
inline _LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(long double) = delete;
387+
388+
template <class _Tp, class = void>
389+
struct __is_ordered_integer_representable : false_type {};
390+
391+
template <class _Tp>
392+
struct __is_ordered_integer_representable<_Tp, __void_t<decltype(std::__to_ordered_integral(std::declval<_Tp>()))>>
393+
: true_type {};
394+
395+
template <class _Tp>
396+
inline constexpr auto __is_ordered_integer_representable_v = __is_ordered_integer_representable<_Tp>::value;
397+
382398
struct __low_byte_fn {
383399
template <class _Ip>
384400
_LIBCPP_HIDE_FROM_ABI constexpr uint8_t operator()(_Ip __integer) const {

libcxx/include/__algorithm/stable_sort.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct __stable_sort_switch {
202202
#if _LIBCPP_STD_VER >= 17
203203
template <class _Tp>
204204
_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() {
205-
static_assert(is_integral_v<_Tp > || numeric_limits<_Tp>::is_iec559);
205+
static_assert(__is_ordered_integer_representable_v<_Tp>);
206206
if constexpr (sizeof(_Tp) == 1) {
207207
return 1 << 8;
208208
}
@@ -212,7 +212,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() {
212212

213213
template <class _Tp>
214214
_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_max_bound() {
215-
static_assert(is_integral_v<_Tp > || numeric_limits<_Tp>::is_iec559);
215+
static_assert(__is_ordered_integer_representable_v<_Tp>);
216216
if constexpr (sizeof(_Tp) >= 8) {
217217
return 1 << 15;
218218
}
@@ -248,7 +248,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort(
248248
#if _LIBCPP_STD_VER >= 17
249249
constexpr auto __default_comp = __desugars_to_v<__less_tag, _Compare, value_type, value_type >;
250250
constexpr auto __arithmetic_value =
251-
(is_integral_v<value_type > || numeric_limits<value_type>::is_iec559) &&
251+
__is_ordered_integer_representable_v<value_type> &&
252252
is_same_v< value_type&, __iter_reference<_RandomAccessIterator>>;
253253
if constexpr (__default_comp && __arithmetic_value) {
254254
if (__len <= __buff_size && __len >= static_cast<difference_type>(std::__radix_sort_min_bound<value_type>()) &&

libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ int main(int, char**) {
250250
test<int>();
251251
test_floating<float>();
252252
test_floating<double>();
253+
test_floating<long double>();
253254
test_enum();
254255
#if TEST_STD_VER >= 26
255256
static_assert(test<int>());

0 commit comments

Comments
 (0)