diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2022-01-04 16:33:33 +0100 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-09-15 14:08:21 +0100 |
commit | d589898f5be6ce8dcf3205a14892b67a3053e962 (patch) | |
tree | 59a6abaa3aac0941ecabf418b949340a25ad9cc5 /Userland/Libraries/LibCrypto | |
parent | 42db468ef576dd338bb11e636f7a33c11b0ce490 (diff) | |
download | serenity-d589898f5be6ce8dcf3205a14892b67a3053e962.zip |
LibCrypto: Add SignedBigInteger::negated_value()
Return the negated value of the current number.
Diffstat (limited to 'Userland/Libraries/LibCrypto')
-rw-r--r-- | Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h | 2 |
2 files changed, 9 insertions, 0 deletions
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); |