Fix division of unlimited ints
This commit is contained in:
parent
8798ee646d
commit
8778898afb
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
#include "storage.hpp"
|
#include "storage.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
@ -220,7 +218,6 @@ private:
|
|||||||
template <size_t MaxBytes>
|
template <size_t MaxBytes>
|
||||||
using Int = BasicInt<LongestElementSuitableType, MaxBytes>;
|
using Int = BasicInt<LongestElementSuitableType, MaxBytes>;
|
||||||
|
|
||||||
constexpr size_t UNLIMITED = std::numeric_limits<size_t>::max();
|
|
||||||
using UnlimitedInt = BasicInt<LongestElementSuitableType, UNLIMITED>;
|
using UnlimitedInt = BasicInt<LongestElementSuitableType, UNLIMITED>;
|
||||||
|
|
||||||
} // namespace mp
|
} // namespace mp
|
||||||
@ -351,13 +351,13 @@ struct Division
|
|||||||
const LongerType MASK = BASE - 1;
|
const LongerType MASK = BASE - 1;
|
||||||
|
|
||||||
// Prepare u (normalized dividend) length m + n + 1
|
// Prepare u (normalized dividend) length m + n + 1
|
||||||
BasicInt<ElementType, TLhs::MAX_BYTES + TRhs::MAX_BYTES + sizeof(ElementType)> u;
|
BasicInt<ElementType, calculate_sum_bytes(calculate_sum_bytes(TLhs::MAX_BYTES, TRhs::MAX_BYTES), sizeof(ElementType))> u;
|
||||||
u.zero();
|
u.zero();
|
||||||
for (size_t i = 0; i < lhs.size_elems(); ++i)
|
for (size_t i = 0; i < lhs.size_elems(); ++i)
|
||||||
u.set(i, lhs.get(i));
|
u.set(i, lhs.get(i));
|
||||||
|
|
||||||
// Prepare v (normalized divisor) length n
|
// Prepare v (normalized divisor) length n
|
||||||
BasicInt<ElementType, TRhs::MAX_BYTES + sizeof(ElementType)> v;
|
BasicInt<ElementType, calculate_sum_bytes(TRhs::MAX_BYTES, sizeof(ElementType))> v;
|
||||||
v.zero();
|
v.zero();
|
||||||
for (size_t i = 0; i < n; ++i)
|
for (size_t i = 0; i < n; ++i)
|
||||||
v.set(i, rhs.get(i));
|
v.set(i, rhs.get(i));
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <limits>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#ifdef __SIZEOF_INT128__
|
#ifdef __SIZEOF_INT128__
|
||||||
@ -137,4 +138,14 @@ constexpr TElem calculate_last_elem_mask()
|
|||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr size_t UNLIMITED = std::numeric_limits<size_t>::max();
|
||||||
|
|
||||||
|
constexpr size_t calculate_sum_bytes(size_t bytes_a, size_t bytes_b)
|
||||||
|
{
|
||||||
|
if (bytes_a == UNLIMITED || bytes_b == UNLIMITED)
|
||||||
|
return UNLIMITED;
|
||||||
|
|
||||||
|
return bytes_a + bytes_b;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mp
|
} // namespace mp
|
||||||
Loading…
x
Reference in New Issue
Block a user