1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +00:00

LibCrypto: Add naive implementation of {Un,}SignedBigInteger::to_double

This commit is contained in:
Idan Horowitz 2021-09-06 21:20:20 +03:00 committed by Linus Groh
parent 62bc238ac3
commit bcdad57670
4 changed files with 16 additions and 0 deletions

View file

@ -63,6 +63,14 @@ u64 SignedBigInteger::to_u64() const
return ~(unsigned_value - 1); // equivalent to `-unsigned_value`, but doesnt trigger UBSAN
}
double SignedBigInteger::to_double() const
{
double unsigned_value = m_unsigned_data.to_double();
if (!m_sign)
return unsigned_value;
return -unsigned_value;
}
FLATTEN SignedBigInteger SignedBigInteger::plus(const SignedBigInteger& other) const
{
// If both are of the same sign, just add the unsigned data and return.