From d589898f5be6ce8dcf3205a14892b67a3053e962 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Tue, 4 Jan 2022 16:33:33 +0100 Subject: [PATCH] LibCrypto: Add SignedBigInteger::negated_value() Return the negated value of the current number. --- Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp | 7 +++++++ Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp index 8d35cc2b4b..6b6690faaf 100644 --- a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp +++ b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp @@ -292,6 +292,13 @@ FLATTEN SignedDivisionResult SignedBigInteger::divided_by(SignedBigInteger const }; } +FLATTEN SignedBigInteger SignedBigInteger::negated_value() const +{ + auto result { *this }; + result.negate(); + return result; +} + u32 SignedBigInteger::hash() const { return m_unsigned_data.hash() * (1 - (2 * m_sign)); diff --git a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h index df2e425ba3..d1b79df5cb 100644 --- a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h +++ b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h @@ -121,6 +121,8 @@ public: [[nodiscard]] SignedBigInteger multiplied_by(UnsignedBigInteger const& other) const; [[nodiscard]] SignedDivisionResult divided_by(UnsignedBigInteger const& divisor) const; + [[nodiscard]] SignedBigInteger negated_value() const; + [[nodiscard]] u32 hash() const; void set_bit_inplace(size_t bit_index);