change anonymous namespace to namespace detail (#54)

This commit is contained in:
Marcin Wojdyr 2021-04-07 15:17:37 +02:00
parent ceb598bfdf
commit f21b2f24cb
3 changed files with 20 additions and 20 deletions

View File

@ -40,7 +40,7 @@ value128 compute_product_approximation(int64_t q, uint64_t w) {
return firstproduct; return firstproduct;
} }
namespace { namespace detail {
/** /**
* For q in (0,350), we have that * For q in (0,350), we have that
* f = (((152170 + 65536) * q ) >> 16); * f = (((152170 + 65536) * q ) >> 16);
@ -59,7 +59,7 @@ namespace {
fastfloat_really_inline int power(int q) noexcept { fastfloat_really_inline int power(int q) noexcept {
return (((152170 + 65536) * q) >> 16) + 63; return (((152170 + 65536) * q) >> 16) + 63;
} }
} // namespace } // namespace detail
// w * 10 ** q // w * 10 ** q
@ -114,7 +114,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3); answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
answer.power2 = int(power(int(q)) + upperbit - lz - binary::minimum_exponent()); answer.power2 = int(detail::power(int(q)) + upperbit - lz - binary::minimum_exponent());
if (answer.power2 <= 0) { // we have a subnormal? if (answer.power2 <= 0) { // we have a subnormal?
// Here have that answer.power2 <= 0 so -answer.power2 >= 0 // Here have that answer.power2 <= 0 so -answer.power2 >= 0
if(-answer.power2 + 1 >= 64) { // if we have more than 64 bits below the minimum exponent, you have a zero for sure. if(-answer.power2 + 1 >= 64) { // if we have more than 64 bits below the minimum exponent, you have a zero for sure.

View File

@ -13,7 +13,7 @@
namespace fast_float { namespace fast_float {
namespace { namespace detail {
/** /**
* Special case +inf, -inf, nan, infinity, -infinity. * Special case +inf, -inf, nan, infinity, -infinity.
* The case comparisons could be made much faster given that we know that the * The case comparisons could be made much faster given that we know that the
@ -78,7 +78,7 @@ fastfloat_really_inline void to_float(bool negative, adjusted_mantissa am, T &va
#endif #endif
} }
} // namespace } // namespace detail
@ -96,7 +96,7 @@ from_chars_result from_chars(const char *first, const char *last,
} }
parsed_number_string pns = parse_number_string(first, last, fmt); parsed_number_string pns = parse_number_string(first, last, fmt);
if (!pns.valid) { if (!pns.valid) {
return parse_infnan(first, last, value); return detail::parse_infnan(first, last, value);
} }
answer.ec = std::errc(); // be optimistic answer.ec = std::errc(); // be optimistic
answer.ptr = pns.lastmatch; answer.ptr = pns.lastmatch;
@ -117,7 +117,7 @@ from_chars_result from_chars(const char *first, const char *last,
// If we called compute_float<binary_format<T>>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0), // If we called compute_float<binary_format<T>>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0),
// then we need to go the long way around again. This is very uncommon. // then we need to go the long way around again. This is very uncommon.
if(am.power2 < 0) { am = parse_long_mantissa<binary_format<T>>(first,last); } if(am.power2 < 0) { am = parse_long_mantissa<binary_format<T>>(first,last); }
to_float(pns.negative, am, value); detail::to_float(pns.negative, am, value);
return answer; return answer;
} }

View File

@ -19,7 +19,7 @@
namespace fast_float { namespace fast_float {
namespace { namespace detail {
// remove all final zeroes // remove all final zeroes
inline void trim(decimal &h) { inline void trim(decimal &h) {
@ -30,7 +30,7 @@ inline void trim(decimal &h) {
uint32_t number_of_digits_decimal_left_shift(const decimal &h, uint32_t shift) { inline uint32_t number_of_digits_decimal_left_shift(const decimal &h, uint32_t shift) {
shift &= 63; shift &= 63;
const static uint16_t number_of_digits_decimal_left_shift_table[65] = { const static uint16_t number_of_digits_decimal_left_shift_table[65] = {
0x0000, 0x0800, 0x0801, 0x0803, 0x1006, 0x1009, 0x100D, 0x1812, 0x1817, 0x0000, 0x0800, 0x0801, 0x0803, 0x1006, 0x1009, 0x100D, 0x1812, 0x1817,
@ -123,7 +123,7 @@ uint32_t number_of_digits_decimal_left_shift(const decimal &h, uint32_t shift) {
return num_new_digits; return num_new_digits;
} }
uint64_t round(decimal &h) { inline uint64_t round(decimal &h) {
if ((h.num_digits == 0) || (h.decimal_point < 0)) { if ((h.num_digits == 0) || (h.decimal_point < 0)) {
return 0; return 0;
} else if (h.decimal_point > 18) { } else if (h.decimal_point > 18) {
@ -150,7 +150,7 @@ uint64_t round(decimal &h) {
} }
// computes h * 2^-shift // computes h * 2^-shift
void decimal_left_shift(decimal &h, uint32_t shift) { inline void decimal_left_shift(decimal &h, uint32_t shift) {
if (h.num_digits == 0) { if (h.num_digits == 0) {
return; return;
} }
@ -192,7 +192,7 @@ void decimal_left_shift(decimal &h, uint32_t shift) {
} }
// computes h * 2^shift // computes h * 2^shift
void decimal_right_shift(decimal &h, uint32_t shift) { inline void decimal_right_shift(decimal &h, uint32_t shift) {
uint32_t read_index = 0; uint32_t read_index = 0;
uint32_t write_index = 0; uint32_t write_index = 0;
@ -238,7 +238,7 @@ void decimal_right_shift(decimal &h, uint32_t shift) {
trim(h); trim(h);
} }
} // end of anonymous namespace } // namespace detail
template <typename binary> template <typename binary>
adjusted_mantissa compute_float(decimal &d) { adjusted_mantissa compute_float(decimal &d) {
@ -281,7 +281,7 @@ adjusted_mantissa compute_float(decimal &d) {
while (d.decimal_point > 0) { while (d.decimal_point > 0) {
uint32_t n = uint32_t(d.decimal_point); uint32_t n = uint32_t(d.decimal_point);
uint32_t shift = (n < num_powers) ? powers[n] : max_shift; uint32_t shift = (n < num_powers) ? powers[n] : max_shift;
decimal_right_shift(d, shift); detail::decimal_right_shift(d, shift);
if (d.decimal_point < -decimal_point_range) { if (d.decimal_point < -decimal_point_range) {
// should be zero // should be zero
answer.power2 = 0; answer.power2 = 0;
@ -302,7 +302,7 @@ adjusted_mantissa compute_float(decimal &d) {
uint32_t n = uint32_t(-d.decimal_point); uint32_t n = uint32_t(-d.decimal_point);
shift = (n < num_powers) ? powers[n] : max_shift; shift = (n < num_powers) ? powers[n] : max_shift;
} }
decimal_left_shift(d, shift); detail::decimal_left_shift(d, shift);
if (d.decimal_point > decimal_point_range) { if (d.decimal_point > decimal_point_range) {
// we want to get infinity: // we want to get infinity:
answer.power2 = binary::infinite_power(); answer.power2 = binary::infinite_power();
@ -319,7 +319,7 @@ adjusted_mantissa compute_float(decimal &d) {
if (n > max_shift) { if (n > max_shift) {
n = max_shift; n = max_shift;
} }
decimal_right_shift(d, n); detail::decimal_right_shift(d, n);
exp2 += int32_t(n); exp2 += int32_t(n);
} }
if ((exp2 - minimum_exponent) >= binary::infinite_power()) { if ((exp2 - minimum_exponent) >= binary::infinite_power()) {
@ -329,15 +329,15 @@ adjusted_mantissa compute_float(decimal &d) {
} }
const int mantissa_size_in_bits = binary::mantissa_explicit_bits() + 1; const int mantissa_size_in_bits = binary::mantissa_explicit_bits() + 1;
decimal_left_shift(d, mantissa_size_in_bits); detail::decimal_left_shift(d, mantissa_size_in_bits);
uint64_t mantissa = round(d); uint64_t mantissa = detail::round(d);
// It is possible that we have an overflow, in which case we need // It is possible that we have an overflow, in which case we need
// to shift back. // to shift back.
if(mantissa >= (uint64_t(1) << mantissa_size_in_bits)) { if(mantissa >= (uint64_t(1) << mantissa_size_in_bits)) {
decimal_right_shift(d, 1); detail::decimal_right_shift(d, 1);
exp2 += 1; exp2 += 1;
mantissa = round(d); mantissa = detail::round(d);
if ((exp2 - minimum_exponent) >= binary::infinite_power()) { if ((exp2 - minimum_exponent) >= binary::infinite_power()) {
answer.power2 = binary::infinite_power(); answer.power2 = binary::infinite_power();
answer.mantissa = 0; answer.mantissa = 0;