mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibCrypto: Make the constructors of (Un)SignedBigInteger templated
This means it can take any (un)signed word of size at most Word. This means the constructor can be disambiguated if we were to add a double constructor :^). This requires a change in just one test.
This commit is contained in:
parent
48ac6ba372
commit
c87d10365b
Notes:
sideshowbarker
2024-07-17 07:42:50 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/c87d10365b Pull-request: https://github.com/SerenityOS/serenity/pull/15029 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/trflynn89
@ -73,7 +73,7 @@ TEST_CASE(test_unsigned_bigint_basic_add_to_accumulator)
|
||||
|
||||
TEST_CASE(test_unsigned_bigint_basic_add_to_empty_accumulator)
|
||||
{
|
||||
Crypto::UnsignedBigInteger num1({});
|
||||
Crypto::UnsignedBigInteger num1 {};
|
||||
Crypto::UnsignedBigInteger num2(10);
|
||||
Crypto::UnsignedBigIntegerAlgorithms::add_into_accumulator_without_allocation(num1, num2);
|
||||
EXPECT_EQ(num1.words(), Vector<u32> { 10 });
|
||||
|
@ -16,9 +16,11 @@ struct SignedDivisionResult;
|
||||
|
||||
class SignedBigInteger {
|
||||
public:
|
||||
SignedBigInteger(i32 x)
|
||||
: m_sign(x < 0)
|
||||
, m_unsigned_data(abs(x))
|
||||
template<typename T>
|
||||
requires(IsSigned<T> && sizeof(T) <= sizeof(i32))
|
||||
SignedBigInteger(T value)
|
||||
: m_sign(value < 0)
|
||||
, m_unsigned_data(abs(static_cast<i32>(value)))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,13 @@ public:
|
||||
using Word = u32;
|
||||
static constexpr size_t BITS_IN_WORD = 32;
|
||||
|
||||
UnsignedBigInteger(Word x) { m_words.append(x); }
|
||||
// This constructor accepts any unsigned with size up to Word.
|
||||
template<typename T>
|
||||
requires(IsIntegral<T> && sizeof(T) <= sizeof(Word))
|
||||
UnsignedBigInteger(T value)
|
||||
{
|
||||
m_words.append(static_cast<Word>(value));
|
||||
}
|
||||
|
||||
explicit UnsignedBigInteger(Vector<Word, STARTING_WORD_SIZE>&& words)
|
||||
: m_words(move(words))
|
||||
|
Loading…
Reference in New Issue
Block a user