Skip to content

Commit 147cf3b

Browse files
committed
type usage fix and cleanup.
1 parent 38d0ab3 commit 147cf3b

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

include/fast_float/decimal_to_binary.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace fast_float {
1717
// most significant bits and the low part corresponding to the least significant
1818
// bits.
1919
//
20-
template <limb_t bit_precision>
20+
template <am_bits_t bit_precision>
2121
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
2222
compute_product_approximation(am_pow_t q, am_mant_t w) noexcept {
2323
am_pow_t const index = 2 * (q - powers::smallest_power_of_five);
@@ -90,7 +90,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
9090
compute_error(am_pow_t q, am_mant_t w) noexcept {
9191
auto const lz = leading_zeroes(w);
9292
w <<= lz;
93-
value128 product =
93+
value128 const product =
9494
compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
9595
return compute_error_scaled<binary>(q, product.high, lz);
9696
}
@@ -201,7 +201,7 @@ compute_float(am_pow_t q, am_mant_t w) noexcept {
201201
answer.mantissa >>= 1;
202202
if (answer.mantissa >= (am_mant_t(2) << binary::mantissa_explicit_bits())) {
203203
answer.mantissa = (am_mant_t(1) << binary::mantissa_explicit_bits());
204-
++answer.power2; // undo previous addition
204+
++answer.power2; // undo previous line addition
205205
}
206206

207207
// Check if we have infinity after computation
@@ -210,6 +210,7 @@ compute_float(am_pow_t q, am_mant_t w) noexcept {
210210
answer.power2 = binary::infinite_power();
211211
answer.mantissa = 0;
212212
}
213+
213214
return answer;
214215
}
215216

include/fast_float/digit_comparison.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ to_extended(T const value) noexcept {
6868
constexpr am_pow_t bias = binary_format<T>::mantissa_explicit_bits() -
6969
binary_format<T>::minimum_exponent();
7070

71-
auto const bits = bit_cast<equiv_uint, T>(value);
71+
auto const bits = bit_cast<equiv_uint>(value);
7272

7373
if ((bits & exponent_mask) == 0) {
7474
// denormal

include/fast_float/float_common.h

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,6 @@ using parse_options = parse_options_t<char>;
120120

121121
} // namespace fast_float
122122

123-
#if FASTFLOAT_HAS_BIT_CAST
124-
#include <bit>
125-
#endif
126-
127-
namespace fast_float {
128-
template <typename To, typename From>
129-
FASTFLOAT_CONSTEXPR20 To bit_cast(const From &from) noexcept {
130-
#if FASTFLOAT_HAS_BIT_CAST
131-
return std::bit_cast<To>(from);
132-
#else
133-
// Implementation of std::bit_cast for pre-C++20.
134-
static_assert(sizeof(To) == sizeof(From),
135-
"bit_cast requires source and destination to be the same size");
136-
auto to = To();
137-
// The cast suppresses a bogus -Wclass-memaccess on GCC.
138-
std::memcpy(static_cast<void *>(&to), &from, sizeof(to));
139-
return to;
140-
#endif
141-
}
142-
} // namespace fast_float
143-
144123
#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
145124
defined(__amd64) || defined(__aarch64__) || defined(_M_ARM64) || \
146125
defined(__MINGW64__) || defined(__s390x__) || \
@@ -269,7 +248,25 @@ FASTFLOAT_CONSTEXPR20 To bit_cast(const From &from) noexcept {
269248
#define FASTFLOAT_ENABLE_IF(...) \
270249
typename std::enable_if<(__VA_ARGS__), int>::type
271250

251+
#if FASTFLOAT_HAS_BIT_CAST
252+
#include <bit>
253+
#endif
254+
272255
namespace fast_float {
256+
template <typename To, typename From>
257+
constexpr fastfloat_really_inline To bit_cast(const From &from) noexcept {
258+
#if FASTFLOAT_HAS_BIT_CAST
259+
return std::bit_cast<To>(from);
260+
#else
261+
// Implementation of std::bit_cast for pre-C++20.
262+
static_assert(sizeof(To) == sizeof(From),
263+
"bit_cast requires source and destination to be the same size");
264+
auto to = To();
265+
// The cast suppresses a bogus -Wclass-memaccess on GCC.
266+
std::memcpy(static_cast<void *>(&to), &from, sizeof(to));
267+
return to;
268+
#endif
269+
}
273270

274271
fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() noexcept {
275272
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED
@@ -1124,7 +1121,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
11241121
word =
11251122
equiv_uint(word | equiv_uint(negative) << binary_format<T>::sign_index());
11261123
#endif
1127-
value = bit_cast<T, equiv_uint>(word);
1124+
value = bit_cast<T>(word);
11281125
}
11291126

11301127
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN

0 commit comments

Comments
 (0)