mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
LibCrypto: Implement a (mostly) proper to_double for UnsignedBigInteger
SignedBigInteger can immediately use this by just negating the double if the sign bit is set. For simple cases (below 2^53) we can just convert via an u64, however above that we need to extract the top 53 bits and use those as the mantissa. This function currently does not behave exactly as the JS spec specifies however it is much less naive than the previous implementation.
This commit is contained in:
parent
2290fbc2a0
commit
8b8cee3172
3 changed files with 241 additions and 71 deletions
|
@ -70,6 +70,8 @@ double SignedBigInteger::to_double() const
|
|||
double unsigned_value = m_unsigned_data.to_double();
|
||||
if (!m_sign)
|
||||
return unsigned_value;
|
||||
|
||||
VERIFY(!is_zero());
|
||||
return -unsigned_value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue