Export of internal Abseil changes

--
756156bf03da050e8b27539a8247d9af7e44c6a2 by Abseil Team <absl-team@google.com>:

Fix a typo in cord.h: "accomodate" => "accommodate"

PiperOrigin-RevId: 356168875

--
638befdb342b608ec28910ee931ee200fdbe1fef by Samuel Benzaquen <sbenza@google.com>:

Fix float conversion for PPC.
In PPC `long double` is a double-double representation which behaves weirdly
wrt numeric_limits. Don't take `long double` into account when we are not
handling `long double` natively anyway.

Fix the convert test to always run the conversion even if we are not going to
compare against libc's printf result. This allows exercising the code itself to
make sure we don't trigger assertions or UB found by sanitizers.

PiperOrigin-RevId: 355857729

--
ff5f893319fa76b273c7785b76ef6c95b1791076 by Abseil Team <absl-team@google.com>:

Example usage tweak

PiperOrigin-RevId: 355695750

--
0efc454f90023fa651b226e5e3ba7395a3b60c6d by Benjamin Barenblat <bbaren@google.com>:

Remove endian-sensitivity from Abseil’s RNG

Ensure that the Abseil random number generator produces identical output
on both big- and little-endian platforms by byte-swapping appropriately
on big-endian systems.

PiperOrigin-RevId: 355635051
GitOrigin-RevId: 756156bf03da050e8b27539a8247d9af7e44c6a2
Change-Id: Iaaa69767b8e85d626742b9ba56fefb75f07c69ee
pull/898/head
Abseil Team 4 years ago committed by Derek Mauro
parent 9c6a50fdd8
commit c36d825d9a
  1. 1
      absl/base/BUILD.bazel
  2. 1
      absl/base/CMakeLists.txt
  3. 61
      absl/base/internal/endian.h
  4. 3
      absl/random/CMakeLists.txt
  5. 7
      absl/random/internal/BUILD.bazel
  6. 3
      absl/random/internal/explicit_seed_seq.h
  7. 8
      absl/random/internal/randen_engine.h
  8. 3
      absl/random/internal/randen_slow_test.cc
  9. 2
      absl/strings/cord.h
  10. 88
      absl/strings/internal/str_format/convert_test.cc
  11. 33
      absl/strings/internal/str_format/float_conversion.cc
  12. 2
      absl/synchronization/mutex.h

@ -479,6 +479,7 @@ cc_library(
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":base",
":config", ":config",
":core_headers", ":core_headers",
], ],

@ -418,6 +418,7 @@ absl_cc_library(
COPTS COPTS
${ABSL_DEFAULT_COPTS} ${ABSL_DEFAULT_COPTS}
DEPS DEPS
absl::base
absl::config absl::config
absl::core_headers absl::core_headers
PUBLIC PUBLIC

@ -26,6 +26,7 @@
#endif #endif
#include <cstdint> #include <cstdint>
#include "absl/base/casts.h"
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/base/internal/unaligned_access.h" #include "absl/base/internal/unaligned_access.h"
#include "absl/base/port.h" #include "absl/base/port.h"
@ -173,6 +174,36 @@ inline constexpr bool IsLittleEndian() { return false; }
#endif /* ENDIAN */ #endif /* ENDIAN */
inline uint8_t FromHost(uint8_t x) { return x; }
inline uint16_t FromHost(uint16_t x) { return FromHost16(x); }
inline uint32_t FromHost(uint32_t x) { return FromHost32(x); }
inline uint64_t FromHost(uint64_t x) { return FromHost64(x); }
inline uint8_t ToHost(uint8_t x) { return x; }
inline uint16_t ToHost(uint16_t x) { return ToHost16(x); }
inline uint32_t ToHost(uint32_t x) { return ToHost32(x); }
inline uint64_t ToHost(uint64_t x) { return ToHost64(x); }
inline int8_t FromHost(int8_t x) { return x; }
inline int16_t FromHost(int16_t x) {
return bit_cast<int16_t>(FromHost16(bit_cast<uint16_t>(x)));
}
inline int32_t FromHost(int32_t x) {
return bit_cast<int32_t>(FromHost32(bit_cast<uint32_t>(x)));
}
inline int64_t FromHost(int64_t x) {
return bit_cast<int64_t>(FromHost64(bit_cast<uint64_t>(x)));
}
inline int8_t ToHost(int8_t x) { return x; }
inline int16_t ToHost(int16_t x) {
return bit_cast<int16_t>(ToHost16(bit_cast<uint16_t>(x)));
}
inline int32_t ToHost(int32_t x) {
return bit_cast<int32_t>(ToHost32(bit_cast<uint32_t>(x)));
}
inline int64_t ToHost(int64_t x) {
return bit_cast<int64_t>(ToHost64(bit_cast<uint64_t>(x)));
}
// Functions to do unaligned loads and stores in little-endian order. // Functions to do unaligned loads and stores in little-endian order.
inline uint16_t Load16(const void *p) { inline uint16_t Load16(const void *p) {
return ToHost16(ABSL_INTERNAL_UNALIGNED_LOAD16(p)); return ToHost16(ABSL_INTERNAL_UNALIGNED_LOAD16(p));
@ -233,6 +264,36 @@ inline constexpr bool IsLittleEndian() { return false; }
#endif /* ENDIAN */ #endif /* ENDIAN */
inline uint8_t FromHost(uint8_t x) { return x; }
inline uint16_t FromHost(uint16_t x) { return FromHost16(x); }
inline uint32_t FromHost(uint32_t x) { return FromHost32(x); }
inline uint64_t FromHost(uint64_t x) { return FromHost64(x); }
inline uint8_t ToHost(uint8_t x) { return x; }
inline uint16_t ToHost(uint16_t x) { return ToHost16(x); }
inline uint32_t ToHost(uint32_t x) { return ToHost32(x); }
inline uint64_t ToHost(uint64_t x) { return ToHost64(x); }
inline int8_t FromHost(int8_t x) { return x; }
inline int16_t FromHost(int16_t x) {
return bit_cast<int16_t>(FromHost16(bit_cast<uint16_t>(x)));
}
inline int32_t FromHost(int32_t x) {
return bit_cast<int32_t>(FromHost32(bit_cast<uint32_t>(x)));
}
inline int64_t FromHost(int64_t x) {
return bit_cast<int64_t>(FromHost64(bit_cast<uint64_t>(x)));
}
inline int8_t ToHost(int8_t x) { return x; }
inline int16_t ToHost(int16_t x) {
return bit_cast<int16_t>(ToHost16(bit_cast<uint16_t>(x)));
}
inline int32_t ToHost(int32_t x) {
return bit_cast<int32_t>(ToHost32(bit_cast<uint32_t>(x)));
}
inline int64_t ToHost(int64_t x) {
return bit_cast<int64_t>(ToHost64(bit_cast<uint64_t>(x)));
}
// Functions to do unaligned loads and stores in big-endian order. // Functions to do unaligned loads and stores in big-endian order.
inline uint16_t Load16(const void *p) { inline uint16_t Load16(const void *p) {
return ToHost16(ABSL_INTERNAL_UNALIGNED_LOAD16(p)); return ToHost16(ABSL_INTERNAL_UNALIGNED_LOAD16(p));

@ -611,6 +611,7 @@ absl_cc_library(
${ABSL_DEFAULT_LINKOPTS} ${ABSL_DEFAULT_LINKOPTS}
DEPS DEPS
absl::config absl::config
absl::endian
TESTONLY TESTONLY
) )
@ -758,6 +759,7 @@ absl_cc_library(
LINKOPTS LINKOPTS
${ABSL_DEFAULT_LINKOPTS} ${ABSL_DEFAULT_LINKOPTS}
DEPS DEPS
absl::endian
absl::random_internal_iostream_state_saver absl::random_internal_iostream_state_saver
absl::random_internal_randen absl::random_internal_randen
absl::raw_logging_internal absl::raw_logging_internal
@ -1119,6 +1121,7 @@ absl_cc_test(
LINKOPTS LINKOPTS
${ABSL_DEFAULT_LINKOPTS} ${ABSL_DEFAULT_LINKOPTS}
DEPS DEPS
absl::endian
absl::random_internal_randen_slow absl::random_internal_randen_slow
gtest_main gtest_main
) )

@ -124,7 +124,10 @@ cc_library(
], ],
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = ["//absl/base:config"], deps = [
"//absl/base:config",
"//absl/base:endian",
],
) )
cc_library( cc_library(
@ -242,6 +245,7 @@ cc_library(
deps = [ deps = [
":iostream_state_saver", ":iostream_state_saver",
":randen", ":randen",
"//absl/base:endian",
"//absl/meta:type_traits", "//absl/meta:type_traits",
], ],
) )
@ -606,6 +610,7 @@ cc_test(
deps = [ deps = [
":platform", ":platform",
":randen_slow", ":randen_slow",
"//absl/base:endian",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

@ -23,6 +23,7 @@
#include <vector> #include <vector>
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/base/internal/endian.h"
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
@ -73,7 +74,7 @@ class ExplicitSeedSeq {
template <typename OutIterator> template <typename OutIterator>
void generate(OutIterator begin, OutIterator end) { void generate(OutIterator begin, OutIterator end) {
for (size_t index = 0; begin != end; begin++) { for (size_t index = 0; begin != end; begin++) {
*begin = state_.empty() ? 0 : state_[index++]; *begin = state_.empty() ? 0 : little_endian::FromHost32(state_[index++]);
if (index >= state_.size()) { if (index >= state_.size()) {
index = 0; index = 0;
} }

@ -23,6 +23,7 @@
#include <limits> #include <limits>
#include <type_traits> #include <type_traits>
#include "absl/base/internal/endian.h"
#include "absl/meta/type_traits.h" #include "absl/meta/type_traits.h"
#include "absl/random/internal/iostream_state_saver.h" #include "absl/random/internal/iostream_state_saver.h"
#include "absl/random/internal/randen.h" #include "absl/random/internal/randen.h"
@ -76,7 +77,7 @@ class alignas(16) randen_engine {
impl_.Generate(state_); impl_.Generate(state_);
} }
return state_[next_++]; return little_endian::ToHost(state_[next_++]);
} }
template <class SeedSequence> template <class SeedSequence>
@ -181,7 +182,8 @@ class alignas(16) randen_engine {
// In the case that `elem` is `uint8_t`, it must be cast to something // In the case that `elem` is `uint8_t`, it must be cast to something
// larger so that it prints as an integer rather than a character. For // larger so that it prints as an integer rather than a character. For
// simplicity, apply the cast all circumstances. // simplicity, apply the cast all circumstances.
os << static_cast<numeric_type>(elem) << os.fill(); os << static_cast<numeric_type>(little_endian::FromHost(elem))
<< os.fill();
} }
os << engine.next_; os << engine.next_;
return os; return os;
@ -200,7 +202,7 @@ class alignas(16) randen_engine {
// necessary to read a wider type and then cast it to uint8_t. // necessary to read a wider type and then cast it to uint8_t.
numeric_type value; numeric_type value;
is >> value; is >> value;
elem = static_cast<result_type>(value); elem = little_endian::ToHost(static_cast<result_type>(value));
} }
is >> next; is >> next;
if (is.fail()) { if (is.fail()) {

@ -17,6 +17,7 @@
#include <cstring> #include <cstring>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/internal/endian.h"
#include "absl/random/internal/randen_traits.h" #include "absl/random/internal/randen_traits.h"
namespace { namespace {
@ -56,7 +57,7 @@ TEST(RandenSlowTest, Default) {
uint64_t* id = d.state; uint64_t* id = d.state;
for (const auto& elem : kGolden) { for (const auto& elem : kGolden) {
EXPECT_EQ(elem, *id++); EXPECT_EQ(absl::little_endian::FromHost64(elem), *id++);
} }
} }

@ -25,7 +25,7 @@
// //
// Because a Cord consists of these chunks, data can be added to or removed from // Because a Cord consists of these chunks, data can be added to or removed from
// a Cord during its lifetime. Chunks may also be shared between Cords. Unlike a // a Cord during its lifetime. Chunks may also be shared between Cords. Unlike a
// `std::string`, a Cord can therefore accomodate data that changes over its // `std::string`, a Cord can therefore accommodate data that changes over its
// lifetime, though it's not quite "mutable"; it can change only in the // lifetime, though it's not quite "mutable"; it can change only in the
// attachment, detachment, or rearrangement of chunks of its constituent data. // attachment, detachment, or rearrangement of chunks of its constituent data.
// //

@ -554,7 +554,8 @@ TEST_F(FormatConvertTest, Uint128) {
} }
template <typename Floating> template <typename Floating>
void TestWithMultipleFormatsHelper(const std::vector<Floating> &floats) { void TestWithMultipleFormatsHelper(const std::vector<Floating> &floats,
const std::set<Floating> &skip_verify) {
const NativePrintfTraits &native_traits = VerifyNativeImplementation(); const NativePrintfTraits &native_traits = VerifyNativeImplementation();
// Reserve the space to ensure we don't allocate memory in the output itself. // Reserve the space to ensure we don't allocate memory in the output itself.
std::string str_format_result; std::string str_format_result;
@ -602,7 +603,16 @@ void TestWithMultipleFormatsHelper(const std::vector<Floating> &floats) {
AppendPack(&str_format_result, format, absl::MakeSpan(args)); AppendPack(&str_format_result, format, absl::MakeSpan(args));
} }
if (string_printf_result != str_format_result) { #ifdef _MSC_VER
// MSVC has a different rounding policy than us so we can't test our
// implementation against the native one there.
continue;
#elif defined(__APPLE__)
// Apple formats NaN differently (+nan) vs. (nan)
if (std::isnan(d)) continue;
#endif
if (string_printf_result != str_format_result &&
skip_verify.find(d) == skip_verify.end()) {
// We use ASSERT_EQ here because failures are usually correlated and a // We use ASSERT_EQ here because failures are usually correlated and a
// bug would print way too many failed expectations causing the test // bug would print way too many failed expectations causing the test
// to time out. // to time out.
@ -616,12 +626,6 @@ void TestWithMultipleFormatsHelper(const std::vector<Floating> &floats) {
} }
TEST_F(FormatConvertTest, Float) { TEST_F(FormatConvertTest, Float) {
#ifdef _MSC_VER
// MSVC has a different rounding policy than us so we can't test our
// implementation against the native one there.
return;
#endif // _MSC_VER
std::vector<float> floats = {0.0f, std::vector<float> floats = {0.0f,
-0.0f, -0.0f,
.9999999f, .9999999f,
@ -635,7 +639,8 @@ TEST_F(FormatConvertTest, Float) {
std::numeric_limits<float>::epsilon(), std::numeric_limits<float>::epsilon(),
std::numeric_limits<float>::epsilon() + 1.0f, std::numeric_limits<float>::epsilon() + 1.0f,
std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity()}; -std::numeric_limits<float>::infinity(),
std::nanf("")};
// Some regression tests. // Some regression tests.
floats.push_back(0.999999989f); floats.push_back(0.999999989f);
@ -664,21 +669,14 @@ TEST_F(FormatConvertTest, Float) {
std::sort(floats.begin(), floats.end()); std::sort(floats.begin(), floats.end());
floats.erase(std::unique(floats.begin(), floats.end()), floats.end()); floats.erase(std::unique(floats.begin(), floats.end()), floats.end());
#ifndef __APPLE__ TestWithMultipleFormatsHelper(floats, {});
// Apple formats NaN differently (+nan) vs. (nan)
floats.push_back(std::nan(""));
#endif
TestWithMultipleFormatsHelper(floats);
} }
TEST_F(FormatConvertTest, Double) { TEST_F(FormatConvertTest, Double) {
#ifdef _MSC_VER // For values that we know won't match the standard library implementation we
// MSVC has a different rounding policy than us so we can't test our // skip verification, but still run the algorithm to catch asserts/sanitizer
// implementation against the native one there. // bugs.
return; std::set<double> skip_verify;
#endif // _MSC_VER
std::vector<double> doubles = {0.0, std::vector<double> doubles = {0.0,
-0.0, -0.0,
.99999999999999, .99999999999999,
@ -692,7 +690,8 @@ TEST_F(FormatConvertTest, Double) {
std::numeric_limits<double>::epsilon(), std::numeric_limits<double>::epsilon(),
std::numeric_limits<double>::epsilon() + 1, std::numeric_limits<double>::epsilon() + 1,
std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(),
-std::numeric_limits<double>::infinity()}; -std::numeric_limits<double>::infinity(),
std::nan("")};
// Some regression tests. // Some regression tests.
doubles.push_back(0.99999999999999989); doubles.push_back(0.99999999999999989);
@ -722,33 +721,29 @@ TEST_F(FormatConvertTest, Double) {
"5084551339423045832369032229481658085593321233482747978262041447231" "5084551339423045832369032229481658085593321233482747978262041447231"
"68738177180919299881250404026184124858368.000000"; "68738177180919299881250404026184124858368.000000";
if (!gcc_bug_22142) { for (int exp = -300; exp <= 300; ++exp) {
for (int exp = -300; exp <= 300; ++exp) { const double all_ones_mantissa = 0x1fffffffffffff;
const double all_ones_mantissa = 0x1fffffffffffff; doubles.push_back(std::ldexp(all_ones_mantissa, exp));
doubles.push_back(std::ldexp(all_ones_mantissa, exp)); if (gcc_bug_22142) {
skip_verify.insert(doubles.back());
} }
} }
if (gcc_bug_22142) { if (gcc_bug_22142) {
for (auto &d : doubles) { using L = std::numeric_limits<double>;
using L = std::numeric_limits<double>; skip_verify.insert(L::max());
double d2 = std::abs(d); skip_verify.insert(L::min()); // NOLINT
if (d2 == L::max() || d2 == L::min() || d2 == L::denorm_min()) { skip_verify.insert(L::denorm_min());
d = 0; skip_verify.insert(-L::max());
} skip_verify.insert(-L::min()); // NOLINT
} skip_verify.insert(-L::denorm_min());
} }
// Remove duplicates to speed up the logic below. // Remove duplicates to speed up the logic below.
std::sort(doubles.begin(), doubles.end()); std::sort(doubles.begin(), doubles.end());
doubles.erase(std::unique(doubles.begin(), doubles.end()), doubles.end()); doubles.erase(std::unique(doubles.begin(), doubles.end()), doubles.end());
#ifndef __APPLE__ TestWithMultipleFormatsHelper(doubles, skip_verify);
// Apple formats NaN differently (+nan) vs. (nan)
doubles.push_back(std::nan(""));
#endif
TestWithMultipleFormatsHelper(doubles);
} }
TEST_F(FormatConvertTest, DoubleRound) { TEST_F(FormatConvertTest, DoubleRound) {
@ -1069,11 +1064,6 @@ TEST_F(FormatConvertTest, ExtremeWidthPrecision) {
} }
TEST_F(FormatConvertTest, LongDouble) { TEST_F(FormatConvertTest, LongDouble) {
#ifdef _MSC_VER
// MSVC has a different rounding policy than us so we can't test our
// implementation against the native one there.
return;
#endif // _MSC_VER
const NativePrintfTraits &native_traits = VerifyNativeImplementation(); const NativePrintfTraits &native_traits = VerifyNativeImplementation();
const char *const kFormats[] = {"%", "%.3", "%8.5", "%9", "%.5000", const char *const kFormats[] = {"%", "%.3", "%8.5", "%9", "%.5000",
"%.60", "%+", "% ", "%-10"}; "%.60", "%+", "% ", "%-10"};
@ -1134,10 +1124,18 @@ TEST_F(FormatConvertTest, LongDouble) {
for (auto d : doubles) { for (auto d : doubles) {
FormatArgImpl arg(d); FormatArgImpl arg(d);
UntypedFormatSpecImpl format(fmt_str); UntypedFormatSpecImpl format(fmt_str);
std::string result = FormatPack(format, {&arg, 1});
#ifdef _MSC_VER
// MSVC has a different rounding policy than us so we can't test our
// implementation against the native one there.
continue;
#endif // _MSC_VER
// We use ASSERT_EQ here because failures are usually correlated and a // We use ASSERT_EQ here because failures are usually correlated and a
// bug would print way too many failed expectations causing the test to // bug would print way too many failed expectations causing the test to
// time out. // time out.
ASSERT_EQ(StrPrint(fmt_str.c_str(), d), FormatPack(format, {&arg, 1})) ASSERT_EQ(StrPrint(fmt_str.c_str(), d), result)
<< fmt_str << " " << StrPrint("%.18Lg", d) << " " << fmt_str << " " << StrPrint("%.18Lg", d) << " "
<< StrPrint("%La", d) << " " << StrPrint("%.1080Lf", d); << StrPrint("%La", d) << " " << StrPrint("%.1080Lf", d);
} }

@ -112,12 +112,22 @@ inline uint64_t DivideBy10WithCarry(uint64_t *v, uint64_t carry) {
return next_carry % divisor; return next_carry % divisor;
} }
constexpr bool IsDoubleDouble() {
// This is the `double-double` representation of `long double`.
// We do not handle it natively. Fallback to snprintf.
return std::numeric_limits<long double>::digits ==
2 * std::numeric_limits<double>::digits;
}
using MaxFloatType =
typename std::conditional<IsDoubleDouble(), double, long double>::type;
// Generates the decimal representation for an integer of the form `v * 2^exp`, // Generates the decimal representation for an integer of the form `v * 2^exp`,
// where `v` and `exp` are both positive integers. // where `v` and `exp` are both positive integers.
// It generates the digits from the left (ie the most significant digit first) // It generates the digits from the left (ie the most significant digit first)
// to allow for direct printing into the sink. // to allow for direct printing into the sink.
// //
// Requires `0 <= exp` and `exp <= numeric_limits<long double>::max_exponent`. // Requires `0 <= exp` and `exp <= numeric_limits<MaxFloatType>::max_exponent`.
class BinaryToDecimal { class BinaryToDecimal {
static constexpr int ChunksNeeded(int exp) { static constexpr int ChunksNeeded(int exp) {
// We will left shift a uint128 by `exp` bits, so we need `128+exp` total // We will left shift a uint128 by `exp` bits, so we need `128+exp` total
@ -132,10 +142,10 @@ class BinaryToDecimal {
static void RunConversion(uint128 v, int exp, static void RunConversion(uint128 v, int exp,
absl::FunctionRef<void(BinaryToDecimal)> f) { absl::FunctionRef<void(BinaryToDecimal)> f) {
assert(exp > 0); assert(exp > 0);
assert(exp <= std::numeric_limits<long double>::max_exponent); assert(exp <= std::numeric_limits<MaxFloatType>::max_exponent);
static_assert( static_assert(
static_cast<int>(StackArray::kMaxCapacity) >= static_cast<int>(StackArray::kMaxCapacity) >=
ChunksNeeded(std::numeric_limits<long double>::max_exponent), ChunksNeeded(std::numeric_limits<MaxFloatType>::max_exponent),
""); "");
StackArray::RunWithCapacity( StackArray::RunWithCapacity(
@ -232,14 +242,14 @@ class BinaryToDecimal {
// Converts a value of the form `x * 2^-exp` into a sequence of decimal digits. // Converts a value of the form `x * 2^-exp` into a sequence of decimal digits.
// Requires `-exp < 0` and // Requires `-exp < 0` and
// `-exp >= limits<long double>::min_exponent - limits<long double>::digits`. // `-exp >= limits<MaxFloatType>::min_exponent - limits<MaxFloatType>::digits`.
class FractionalDigitGenerator { class FractionalDigitGenerator {
public: public:
// Run the conversion for `v * 2^exp` and call `f(generator)`. // Run the conversion for `v * 2^exp` and call `f(generator)`.
// This function will allocate enough stack space to perform the conversion. // This function will allocate enough stack space to perform the conversion.
static void RunConversion( static void RunConversion(
uint128 v, int exp, absl::FunctionRef<void(FractionalDigitGenerator)> f) { uint128 v, int exp, absl::FunctionRef<void(FractionalDigitGenerator)> f) {
using Limits = std::numeric_limits<long double>; using Limits = std::numeric_limits<MaxFloatType>;
assert(-exp < 0); assert(-exp < 0);
assert(-exp >= Limits::min_exponent - 128); assert(-exp >= Limits::min_exponent - 128);
static_assert(StackArray::kMaxCapacity >= static_assert(StackArray::kMaxCapacity >=
@ -871,10 +881,10 @@ void FormatA(const HexFloatTypeParams float_traits, Int mantissa, int exp,
// This buffer holds the "0x1.ab1de3" portion of "0x1.ab1de3pe+2". Compute the // This buffer holds the "0x1.ab1de3" portion of "0x1.ab1de3pe+2". Compute the
// size with long double which is the largest of the floats. // size with long double which is the largest of the floats.
constexpr size_t kBufSizeForHexFloatRepr = constexpr size_t kBufSizeForHexFloatRepr =
2 // 0x 2 // 0x
+ std::numeric_limits<long double>::digits / 4 // number of hex digits + std::numeric_limits<MaxFloatType>::digits / 4 // number of hex digits
+ 1 // round up + 1 // round up
+ 1; // "." (dot) + 1; // "." (dot)
char digits_buffer[kBufSizeForHexFloatRepr]; char digits_buffer[kBufSizeForHexFloatRepr];
char *digits_iter = digits_buffer; char *digits_iter = digits_buffer;
const char *const digits = const char *const digits =
@ -1393,10 +1403,7 @@ bool FloatToSink(const Float v, const FormatConversionSpecImpl &conv,
bool ConvertFloatImpl(long double v, const FormatConversionSpecImpl &conv, bool ConvertFloatImpl(long double v, const FormatConversionSpecImpl &conv,
FormatSinkImpl *sink) { FormatSinkImpl *sink) {
if (std::numeric_limits<long double>::digits == if (IsDoubleDouble()) {
2 * std::numeric_limits<double>::digits) {
// This is the `double-double` representation of `long double`.
// We do not handle it natively. Fallback to snprintf.
return FallbackToSnprintf(v, conv, sink); return FallbackToSnprintf(v, conv, sink);
} }

@ -147,7 +147,7 @@ class ABSL_LOCKABLE Mutex {
// //
// Example usage: // Example usage:
// namespace foo { // namespace foo {
// ABSL_CONST_INIT Mutex mu(absl::kConstInit); // ABSL_CONST_INIT absl::Mutex mu(absl::kConstInit);
// } // }
explicit constexpr Mutex(absl::ConstInitType); explicit constexpr Mutex(absl::ConstInitType);

Loading…
Cancel
Save