Skip to content

Commit 3146e68

Browse files
committed
introduce equiv_uint_t
1 parent 82865ad commit 3146e68

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

include/fast_float/digit_comparison.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ scientific_exponent(parsed_number_string_t<UC> &num) noexcept {
6262
template <typename T>
6363
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
6464
to_extended(T value) noexcept {
65-
using equiv_uint = typename binary_format<T>::equiv_uint;
65+
using equiv_uint = equiv_uint_t<T>;
6666
constexpr equiv_uint exponent_mask = binary_format<T>::exponent_mask();
6767
constexpr equiv_uint mantissa_mask = binary_format<T>::mantissa_mask();
6868
constexpr equiv_uint hidden_bit_mask = binary_format<T>::hidden_bit_mask();

include/fast_float/float_common.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ struct is_supported_float_type
230230
> {
231231
};
232232

233+
template <typename T>
234+
using equiv_uint_t = typename std::conditional<
235+
sizeof(T) == 1, uint8_t,
236+
typename std::conditional<
237+
sizeof(T) == 2, uint16_t,
238+
typename std::conditional<sizeof(T) == 4, uint32_t,
239+
uint64_t>::type>::type>::type;
240+
233241
template <typename T> struct is_supported_integer_type : std::is_integral<T> {};
234242

235243
template <typename UC>
@@ -413,8 +421,7 @@ constexpr uint64_t constant_55555 = 5 * 5 * 5 * 5 * 5;
413421
template <typename T, typename U = void> struct binary_format_lookup_tables;
414422

415423
template <typename T> struct binary_format : binary_format_lookup_tables<T> {
416-
using equiv_uint =
417-
typename std::conditional<sizeof(T) == 4, uint32_t, uint64_t>::type;
424+
using equiv_uint = equiv_uint_t<T>;
418425

419426
static inline constexpr int mantissa_explicit_bits();
420427
static inline constexpr int minimum_exponent();
@@ -694,11 +701,10 @@ binary_format<double>::hidden_bit_mask() {
694701
template <typename T>
695702
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
696703
to_float(bool negative, adjusted_mantissa am, T &value) {
697-
using fastfloat_uint = typename binary_format<T>::equiv_uint;
698-
fastfloat_uint word = (fastfloat_uint)am.mantissa;
699-
word |= fastfloat_uint(am.power2)
700-
<< binary_format<T>::mantissa_explicit_bits();
701-
word |= fastfloat_uint(negative) << binary_format<T>::sign_index();
704+
using equiv_uint = equiv_uint_t<T>;
705+
equiv_uint word = equiv_uint(am.mantissa);
706+
word |= equiv_uint(am.power2) << binary_format<T>::mantissa_explicit_bits();
707+
word |= equiv_uint(negative) << binary_format<T>::sign_index();
702708
#if FASTFLOAT_HAS_BIT_CAST
703709
value = std::bit_cast<T>(word);
704710
#else
@@ -841,6 +847,21 @@ fastfloat_really_inline constexpr uint64_t min_safe_u64(int base) {
841847
return int_luts<>::min_safe_u64[base - 2];
842848
}
843849

850+
static_assert(std::is_same<equiv_uint_t<double>, uint64_t>::value,
851+
"equiv_uint should be uint64_t for double");
852+
static_assert(std::is_same<equiv_uint_t<float>, uint32_t>::value,
853+
"equiv_uint should be uint32_t for float");
854+
855+
#ifdef __STDCPP_FLOAT64_T__
856+
static_assert(std::is_same<equiv_uint_t<std::float64_t>, uint64_t>::value,
857+
"equiv_uint should be uint64_t for std::float64_t");
858+
#endif
859+
860+
#ifdef __STDCPP_FLOAT32_T__
861+
static_assert(std::is_same<equiv_uint_t<std::float32_t>, uint32_t>::value,
862+
"equiv_uint should be uint32_t for std::float32_t");
863+
#endif
864+
844865
constexpr chars_format operator~(chars_format rhs) noexcept {
845866
using int_type = std::underlying_type<chars_format>::type;
846867
return static_cast<chars_format>(~static_cast<int_type>(rhs));

tests/basictest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ constexpr void check_basic_test_result(stringtype str, result_type result,
729729
auto copysign = [](double x, double y) -> double {
730730
#if FASTFLOAT_HAS_BIT_CAST
731731
if (fast_float::cpp20_and_in_constexpr()) {
732-
using equiv_int = std::make_signed_t<
733-
typename fast_float::binary_format<double>::equiv_uint>;
732+
using equiv_int = std::make_signed_t<fast_float::equiv_uint_t<double>>;
734733
auto const i = std::bit_cast<equiv_int>(y);
735734
if (i < 0) {
736735
return -x;

0 commit comments

Comments
 (0)