Changes imported from Abseil "staging" branch:
- c77facb7ba7c12d656e213e5d63d7dcd9d1f56ba Present the Writer* methods as an option, rather than an ... by Abseil Team <absl-team@google.com> - c6004d718f185868dee2ec48b4de6425399b062d Split exception_safety_testing out into its own cmake rul... by Jon Cohen <cohenjon@google.com> - 9aa6fc7b34674472d808ed8021f3b20faea82f78 Downstream https://github.com/abseil/abseil-cpp/pull/69 by Jon Cohen <cohenjon@google.com> - 13d340269f284b815cc409d2271099e535f4cba4 Internal change by Jon Cohen <cohenjon@google.com> - 51840a9243ac9d47eb3c177398d10bb3341f3230 Fix assertion in conversion from floating point types to ... by Alex Strelnikov <strel@google.com> GitOrigin-RevId: c77facb7ba7c12d656e213e5d63d7dcd9d1f56ba Change-Id: I7590561b04a986ffbec7139bb9c3aea319a3b975
This commit is contained in:
parent
e5c6ee2d00
commit
f4f238b09b
7 changed files with 34 additions and 19 deletions
|
@ -104,11 +104,15 @@ void DivModImpl(uint128 dividend, uint128 divisor, uint128* quotient_ret,
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
uint128 Initialize128FromFloat(T v) {
|
||||
uint128 MakeUint128FromFloat(T v) {
|
||||
static_assert(std::is_floating_point<T>::value, "");
|
||||
|
||||
// Rounding behavior is towards zero, same as for built-in types.
|
||||
|
||||
// Undefined behavior if v is NaN or cannot fit into uint128.
|
||||
assert(!std::isnan(v) && v > -1 && v < std::ldexp(static_cast<T>(1), 128));
|
||||
assert(std::isfinite(v) && v > -1 &&
|
||||
(std::numeric_limits<T>::max_exponent <= 128 ||
|
||||
v < std::ldexp(static_cast<T>(1), 128)));
|
||||
|
||||
if (v >= std::ldexp(static_cast<T>(1), 64)) {
|
||||
uint64_t hi = static_cast<uint64_t>(std::ldexp(v, -64));
|
||||
|
@ -120,9 +124,9 @@ uint128 Initialize128FromFloat(T v) {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
uint128::uint128(float v) : uint128(Initialize128FromFloat(v)) {}
|
||||
uint128::uint128(double v) : uint128(Initialize128FromFloat(v)) {}
|
||||
uint128::uint128(long double v) : uint128(Initialize128FromFloat(v)) {}
|
||||
uint128::uint128(float v) : uint128(MakeUint128FromFloat(v)) {}
|
||||
uint128::uint128(double v) : uint128(MakeUint128FromFloat(v)) {}
|
||||
uint128::uint128(long double v) : uint128(MakeUint128FromFloat(v)) {}
|
||||
|
||||
uint128& uint128::operator/=(uint128 other) {
|
||||
uint128 quotient = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue